-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Wileynet wrote:
Here is another beginner question of sorts I imagine. I receive this error. java.sql.SQLException: Update failed, possible duplicate entry
I've got this code in a .jsp page.
<% String ref=request.getHeader("Referer");%>
<BR>
<% count.addInfo( ref );
%>
count is calling the method addInfo in a java bean...
public void addInfo( String Referer )
throws SQLException, Exception {
if (con != null) {
try{
PreparedStatement updateInfo;
updateInfo = con.prepareStatement(
"insert into info(?);");
updateInfo.setString(1,Referer);
updateInfo.execute();
}
catch (SQLException sqle) {
error = "Update failed, possible duplicate entry";
throw new SQLException( error );
}
} else {
error = "Connection with database was lost.";
throw new Exception( error );
}
}
Can anyone see the mistake I am making here. My database has one table now called info with one String field which is the primary key also.
The SQLException doesn't necessarily mean 'duplicate' entry. Could you print out the SQLException's stack trace?
You also want to consider not re-throwing a different exception in code like this, as you're 'masking' the original error :(
-Mark
- -- MySQL 2003 Users Conference -> http://www.mysql.com/events/uc2003/
For technical support contracts, visit https://order.mysql.com/?ref=mmma
__ ___ ___ ____ __ / |/ /_ __/ __/ __ \/ / Mark Matthews <[EMAIL PROTECTED]> / /|_/ / // /\ \/ /_/ / /__ MySQL AB, Full-Time Developer - JDBC/Java /_/ /_/\_, /___/\___\_\___/ Flossmoor (Chicago), IL USA <___/ www.mysql.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.1.90 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE+f8vltvXNTca6JD8RAnxYAJ9B/Plm7OKowTowaZABDPgwGcLonQCfdKXR A3LbfN+c0q1N3qVK9KF/iQ4= =ptrc -----END PGP SIGNATURE-----
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]