package com.metastores.test.bugreport; import java.sql.*; public class MySQLLongString { protected static Connection connection = null; protected static ResultSet rs = null; protected static Statement stmt = null; public static void main(String args[]) { try { test(); } catch (Exception e) { System.out.println("Exception occured!"); e.printStackTrace(System.out); } finally { try { if (rs!=null) rs.close(); if (stmt!=null) stmt.close(); if (connection!=null) connection.close(); } catch (SQLException e) { } } } public static void test() throws Exception { String driverClass = "org.gjt.mm.mysql.Driver"; String url = "jdbc:mysql://localhost/metastores"; String username = "tux"; String password = "bsd"; //Load driver and get connection Class.forName(driverClass).newInstance(); connection = DriverManager.getConnection(url, username, password); //Create table update("CREATE TABLE A(B VARCHAR(255))"); //Create a string that is too long StringBuffer tooLongString = new StringBuffer(265); for (int i=0; i<265; i++) { tooLongString.append(""+(i%10)); } //Debug System.out.println(".main() original string is "+tooLongString.toString()); System.out.println(".main() original string length is "+tooLongString.length()); //Insert it (no error!) String insert = "INSERT INTO A(B) VALUES('"+tooLongString.toString()+"')"; update(insert); //Read it back ResultSet rs = null; Statement stmt = null; stmt = connection.createStatement(); rs = stmt.executeQuery("SELECT B FROM A"); if (!rs.next()) { System.out.println("Data not found!"); System.exit(1); } String readBack = rs.getString(1); System.out.println(".main() string read back is "+readBack); System.out.println(".main() string read back length is "+readBack.length()); } protected static void update(String u) throws SQLException { try { stmt = connection.createStatement(); stmt.executeUpdate(u); } finally { if (stmt!=null) stmt.close(); stmt = null; } } }