The SQL Insert statement usually looks like this:
Insert into info(referer) value('?');
Your statement looks like it is going try and update a field with name =
(what ever you pass in for referer). And no such field exists in your
db, moreover you are not providing a value for the field.
Hope this helps
Kal
-----Original Message-----
From: Wileynet [mailto:[EMAIL PROTECTED]
Sent: Monday, March 24, 2003 11:38 PM
To: 'Tomcat Users List'
Subject: RE: java.sql.SQLException: Update failed, possible duplicate
entry
Ok, I tried that. Here is the new code....
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) {
System.err.println( "HELP" + sqle );
}
}
else {
error = "Connection with database was lost.";
throw new Exception( error );
}
}
Now, I get no error but the database does not get updated ? This is
basically my database - >
mysql> desc info;
+-------------+-----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------+------+-----+---------+-------+
| PRIMARY_KEY | int(11) | | PRI | 0 | |
| REFERER | char(200) | YES | | NULL | |
+-------------+-----------+------+-----+---------+-------+
Please help again :)
-----Original Message-----
From: Mark Matthews [mailto:[EMAIL PROTECTED]
Sent: Monday, March 24, 2003 7:26 PM
To: Wileynet
Cc: [EMAIL PROTECTED]
Subject: Re: java.sql.SQLException: Update failed, possible duplicate
entry
-----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.
>
> Thanks if anyone can help or point me to a webpage or something.
>
> -wiley
Also, looking at your code, you have a SQL syntax error. Only the mysql
command-line client requires statements terminated with a ";", so you
should write:
updateInfo = con.prepareStatement("insert into info(?)");
not:
updateInfo = con.prepareStatement("insert into info(?);");
-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+f8xFtvXNTca6JD8RAhArAJ98UE5FFTYc4iok9r62OgjJiIFm+QCgnnhk
oxDuUCf1Qz/tOIzNCkEQcV4=
=VwpN
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]