-
Bug
-
Resolution: Fixed
-
P4
-
1.1.7
-
005
-
x86
-
windows_nt
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2026790 | 1.3.0 | J. Duke | P4 | Resolved | Fixed | beta |
JDK-2026789 | 1.2.2_005 | J. Duke | P4 | Closed | Fixed | 005 |
JDK-2026788 | 1.2.1_002 | J. Duke | P4 | Resolved | Fixed | b02 |
JDK-2026787 | 1.1.8_001 | J. Duke | P4 | Resolved | Fixed | b01 |
9646
The preparedStatement.setString() method truncates strings that are
longer than 254 bytes.
The testcase completes sucessfully when the string length is 254 and
fails when it is >=255.
--------------------------------------------------------------------------
import java.sql.*;
/**
* preparedStatement.setString() truncate string is its lenght > 254.
*
* usage: LargeInsertProblemInJDBC_ODBCBridige DBURL STR_LEN
*
* DBURL -- database to use
* STR_LEN -- length of string to insert
*
* It seems that JdbcOdbc bridge are convert setString() to SQL_CHAR which has
* a length limit of 254. According to JDBC, the
* preparedStatement.setString(int parameterIndex, String x) set a parameter
* to a Java String value. The driver should convert this to a SQL VARCHAR
* or LONGVARCHAR value,
*/
public class LargeInsert
{
private String url = null;
private int len = 0;
public LargeInsert( String dbUrl, String insertLen )
{
url = dbUrl;
try {
len = Integer.parseInt( insertLen );
if ( len > 2000 ) len = 2000;
}
catch( NumberFormatException e ) {
len = 2000;
}
}
public void doIt()
{
String createTableStmt = "create table mytable (longestr varchar(2000))";
String insertStmt = "insert into mytable values( ? )";
String drobTableStmt = "drop table mytable";
boolean tableCreated = false;
Connection con = null;
try {
//
// Load the driver and get a connection
//
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
con = DriverManager.getConnection( "jdbc:odbc:PMB2", "pmb", "coalport" );
System.out.println( "got a connection" );
//
// Create the table
//
Statement stmt = con.createStatement();
stmt.executeUpdate( createTableStmt );
stmt.close();
con.commit();
tableCreated = true;
System.out.println( "table created" );
//
// Attempt an insert of a large string
//
PreparedStatement pstmt = con.prepareStatement( insertStmt );
char buffer[] = new char[ len ];
for( int i = 0; i < len; ++i ) { buffer[i] = 'z'; }
String bufferStr = new String( buffer );
pstmt.setString( 1, bufferStr );
pstmt.executeUpdate();
pstmt.close();
con.commit();
System.out.println( "insert complete" );
}
catch( Exception e) {
System.out.println( "Test failed with:" );
e.printStackTrace();
}
finally {
if ( tableCreated) {
try {
//
// Drop the table
//
Statement stmt = con.createStatement();
stmt.executeUpdate( drobTableStmt );
stmt.close();
con.commit();
System.out.println( "table dropped" );
//
// Close the connection
//
con.close();
System.out.println( "connection closed" );
}
catch( Exception e ) {
System.out.println( "cleanup failed with:" );
e.printStackTrace();
}
}
}
}
public static void main( String args[] )
{
if ( args.length < 2 ) {
System.out.println( "usage: LargeInsertProblemInJDBC_ODBCBridige DBURL STR_LEN" );
} else {
LargeInsert test = new LargeInsert( args[0], args[1] );
test.doIt();
}
}
}
The preparedStatement.setString() method truncates strings that are
longer than 254 bytes.
The testcase completes sucessfully when the string length is 254 and
fails when it is >=255.
--------------------------------------------------------------------------
import java.sql.*;
/**
* preparedStatement.setString() truncate string is its lenght > 254.
*
* usage: LargeInsertProblemInJDBC_ODBCBridige DBURL STR_LEN
*
* DBURL -- database to use
* STR_LEN -- length of string to insert
*
* It seems that JdbcOdbc bridge are convert setString() to SQL_CHAR which has
* a length limit of 254. According to JDBC, the
* preparedStatement.setString(int parameterIndex, String x) set a parameter
* to a Java String value. The driver should convert this to a SQL VARCHAR
* or LONGVARCHAR value,
*/
public class LargeInsert
{
private String url = null;
private int len = 0;
public LargeInsert( String dbUrl, String insertLen )
{
url = dbUrl;
try {
len = Integer.parseInt( insertLen );
if ( len > 2000 ) len = 2000;
}
catch( NumberFormatException e ) {
len = 2000;
}
}
public void doIt()
{
String createTableStmt = "create table mytable (longestr varchar(2000))";
String insertStmt = "insert into mytable values( ? )";
String drobTableStmt = "drop table mytable";
boolean tableCreated = false;
Connection con = null;
try {
//
// Load the driver and get a connection
//
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
con = DriverManager.getConnection( "jdbc:odbc:PMB2", "pmb", "coalport" );
System.out.println( "got a connection" );
//
// Create the table
//
Statement stmt = con.createStatement();
stmt.executeUpdate( createTableStmt );
stmt.close();
con.commit();
tableCreated = true;
System.out.println( "table created" );
//
// Attempt an insert of a large string
//
PreparedStatement pstmt = con.prepareStatement( insertStmt );
char buffer[] = new char[ len ];
for( int i = 0; i < len; ++i ) { buffer[i] = 'z'; }
String bufferStr = new String( buffer );
pstmt.setString( 1, bufferStr );
pstmt.executeUpdate();
pstmt.close();
con.commit();
System.out.println( "insert complete" );
}
catch( Exception e) {
System.out.println( "Test failed with:" );
e.printStackTrace();
}
finally {
if ( tableCreated) {
try {
//
// Drop the table
//
Statement stmt = con.createStatement();
stmt.executeUpdate( drobTableStmt );
stmt.close();
con.commit();
System.out.println( "table dropped" );
//
// Close the connection
//
con.close();
System.out.println( "connection closed" );
}
catch( Exception e ) {
System.out.println( "cleanup failed with:" );
e.printStackTrace();
}
}
}
}
public static void main( String args[] )
{
if ( args.length < 2 ) {
System.out.println( "usage: LargeInsertProblemInJDBC_ODBCBridige DBURL STR_LEN" );
} else {
LargeInsert test = new LargeInsert( args[0], args[1] );
test.doIt();
}
}
}
- backported by
-
JDK-2026787 Large strings being truncated.
- Resolved
-
JDK-2026788 Large strings being truncated.
- Resolved
-
JDK-2026790 Large strings being truncated.
- Resolved
-
JDK-2026789 Large strings being truncated.
- Closed