3 messages in com.mysql.lists.javaRE: MySQL 4.1.3, Connector/J 3.1.2, U...
FromSent OnAttachments
Benzinger, Michael04 Jul 2004 08:31 
Benzinger, Michael04 Jul 2004 12:30 
Mark Matthews04 Jul 2004 13:52 
Subject:RE: MySQL 4.1.3, Connector/J 3.1.2, Unable to Insert
From:Benzinger, Michael (Mich@sabre-holdings.com)
Date:07/04/2004 12:30:49 PM
List:com.mysql.lists.java

Hi again,

I believe I have found the source of my heartburn. At least the rows now insert
without error. I commented out the following line in the files
ServerPreparedStatement.java and all started working properly. Here are the line
numbers with line 1185 commented out:

1184 if (mysql.versionMeetsMinimum(4, 1, 2)) { 1185 //MAB nullCount = (this.parameterCount + 9) / 8; 1186 }

This file was modified in the following directory:

./mysql-connector-java-3.1.2-alpha/com/mysql/jdbc

Mike Benzinger

-----Original Message----- From: Benzinger, Michael Sent: Sun 7/4/04 10:32 To: ja@lists.mysql.com Cc: Subject: MySQL 4.1.3, Connector/J 3.1.2, Unable to Insert Hi,

I am looking for a little assistance. The following setup works = flawlessly using MySQL 4.0.20 and Connector/J 3.0.10. I am using Fedora = Core 2. Here is the relevant information and script. I am unable to = insert a row with the database indicating that I am trying to insert a = null value in a non-null column.

Mike Benzinger

[myhost]:temp> java -version java version "1.4.2_04" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05) Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)

[myhost]:temp> uname -a Linux myhost 2.6.6-1.435.2.3-t9100 #1 Sat Jul 3 08:10:24 CDT 2004 i686 i686 i386
GNU/Linux

[myhost]:temp> rpm -qa | grep -i mysql MySQL-client-4.1.3-0 MySQL-server-4.1.3-0 MySQL-devel-4.1.3-0 MySQL-shared-4.1.3-0

[myhost]:temp> cat testit.sql create database if not exists xyzdb; use xyzdb;

drop table if exists xyz; create table xyz ( a datetime not null , b varchar(3) not null , c varchar(3) not null , d tinyint not null , e bool not null , f varchar(15) not null , g varchar(25) ) ;

alter table xyz add primary key ( a , b , c , d , e , f ) ;

[myhost]:temp> mysql --version mysql Ver 14.5 Distrib 4.1.3-beta, for pc-linux (i686)

[myhost]:temp> mysql mysql -u root -p Enter password: Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 58 to server version: 4.1.3-beta-standard

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show databases; +-----------+ | Database | +-----------+ | mysql | | test | +-----------+ 10 rows in set (0.00 sec)

mysql> \. testit.sql Query OK, 1 row affected (0.00 sec)

Database changed Query OK, 0 rows affected, 1 warning (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0

mysql> show databases; +-----------+ | Database | +-----------+ | mysql | | test | | xyzdb | +-----------+ 11 rows in set (0.00 sec)

mysql> \q Bye

[myhost]:temp> cat testit.java import java.sql.*;

class testit { public static void main(String args[]) { try { Class.forName("com.mysql.jdbc.Driver");

Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost/xyzdb?user=me&password=secret");

System.out.println("Database Version: " +
conn.getMetaData().getDatabaseProductVersion()); System.out.println("Driver Version: " +
conn.getMetaData().getDriverVersion() );

PreparedStatement stmt = conn.prepareStatement(sqlInsert);

Timestamp timestamp = new
Timestamp(Calendar.getInstance().getTimeInMillis());

stmt.setTimestamp(1, timestamp); stmt.setString (2, "xxx" ); stmt.setString (3, "yyy" ); stmt.setInt (4, 3 ); stmt.setBoolean (5, true); stmt.setString (6, "Hello World" ); stmt.setString (7, "OK" );

System.out.println(stmt);

stmt.executeUpdate(); stmt.close();

conn.close(); }

catch (Exception e) { e.printStackTrace(); } }

private static final String sqlInsert = "replace into xyz" + " (" + " a" + " , b" + " , c" + " , d" + " , e" + " , f" + " , g" + " )" + " " + " values" + " (?,?,?,?,?,?,?)" ; }

[myhost]:temp> javac testit.java [myhost]:temp> java -cp
.:mysql-connector-java-3.1.2-alpha/mysql-connector-java-3.1.2-alpha-bin.jar
testit Database Version: 4.1.3-beta-standard Driver Version: mysql-connector-java-3.1.2-alpha ( $Date: 2004/05/20 20:34:41
$, $Revision: 1.27.4.34 $ ) com.mysql.jdbc.ServerPreparedStatement[1] - replace into xyz ( a , b
, c , d , e , f , g ) values ('2004-07-04
10:11:16','xxx','yyy',3,1,'Hello World','OK'[B@443226 java.sql.SQLException: Column 'a' cannot be null at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2551) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1443) at
com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1239) at
com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:903) at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1871) at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1796) at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1658) at testit.main(testit.java:27)