PROBLEM with your JDBC driver - mysql connector.

I am developing using jdk1.4.1 on Mac OS X. I am using the mysql
driver - mysql connector java 2.0.14. I am creating a table in mysql
thru java ... the code to do this is below:

try
{
Statement stmt = con.createStatement();

stmt.executeUpdate( "CREATE TABLE PARTICIPANT ("
+
"LOGINID INTEGER NOT NULL, "
+
"USERNAME VARCHAR (20) NOT NULL, " +
"PASSWORD VARCHAR (20) NOT NULL, "
+
"FIRSTNAME VARCHAR (20) NOT NULL, "
+
"LASTNAME VARCHAR (20) NOT NULL,"
+
"EMAILADD VARCHAR (20) NOT NULL,"
+
"ORGANIZATION VARCHAR (20) NOT NULL," +
"ENABLED BIT NOT NULL,"
+
"GRADELEVELS VARCHAR (80)," +
"PRIMARY KEY( LOGINID )"
+
")");

stmt.close();
}
catch(SQLException ex)
{
ex.printStackTrace();
}

The table gets created properly. I check this from the mysql prompt.


Now i insert 2 records in the table above thru my java code . The
code
that does that is below:

try
{
Statement stmt = con.createStatement();

PreparedStatement pstmt = con.prepareStatement("INSERT
INTO PARTICIPANT VALUES"
+
"(?,?,?,?,?,?,?,?,?)");
pstmt.setInt(1, p.getLoginId());
pstmt.setString(2, p.getUserName());
pstmt.setString(3, p.getPassword());
pstmt.setString(4, p.getFirstName());
pstmt.setString(5, p.getLastName());
pstmt.setString(6, p.getEmailAdd());
pstmt.setString(7, p.getOrganizationName());
pstmt.setBoolean(8, p.isEnabled());
pstmt.setString(9, (new
DataTypeConverter()).getString(p.getGradeLevels()));

pstmt.executeUpdate();

pstmt.close();

}
catch(SQLException ex)
{
ex.printStackTrace();
}

For both the above sniplets of code i am using a connection object
from a pool of connections that i create to the database at start of
application startup. These connections are closed when the
application
exits.

PROBLEM:

The records get inserted in a blank table when i use my java code to
do so. When i delete a record from the table from the mysql prompt and
then go back to my java code to insert the same record it gives me
the following error:

java.sql.SQLException: Invalid argument value: Duplicate entry '1' for
key 1
at com.mysql.jdbc.MysqlIO.sendCommand(Unknown Source)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(Unknown Source)
at com.mysql.jdbc.Connection.execSQL(Unknown Source)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Unknown
Source)
at com.mysql.jdbc.PreparedStatement.executeUpdate(Unknown
Source)
at

com.wavesinmotion.cw.classes.db.DBWriter.setParticipant(DBWriter.java:8 5
)
at
com.wavesinmotion.cw.classes.db.DBWriter.main(DBWriter.java:36)

This i dont understand since the record with that primary key i have
already deleted from the mysql prompt.

When i try to enter a record with the same key using the mysql
prompt
the record successfully gets inserted into the table;

I suspect a bug in your jdbc driver .. .whats the solution or fix to
this ?

regards,
Mufaddal.

---------------------------------------------------------------------
Before posting, please check:
  http://www.mysql.com/manual.php   (the manual)
  http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to