1 21 22 package org.apache.derbyTesting.functionTests.tests.lang; 23 24 import java.sql.Connection ; 25 import java.sql.DriverManager ; 26 import java.sql.ResultSetMetaData ; 27 import java.sql.ResultSet ; 28 import java.sql.Statement ; 29 import java.sql.SQLException ; 30 import java.sql.Types ; 31 32 import org.apache.derby.tools.ij; 33 import org.apache.derby.tools.JDBCDisplayUtil; 34 import java.io.*; 35 import java.sql.PreparedStatement ; 36 37 40 41 42 public class longStringColumn { 43 44 public static PreparedStatement psSet; 45 public static PreparedStatement psGet; 46 47 public static void main(String [] args) { 48 49 System.out.println("Test longStringColumn starting"); 50 51 String longText; 52 StringBuffer buff = new StringBuffer ("... "); 53 54 try { 55 ij.getPropertyArg(args); 58 Connection conn = ij.startJBMS(); 59 60 Statement st2 = conn.createStatement(); 61 st2.execute("CREATE TABLE TEST(id bigint, body clob(65K))"); 62 psSet = conn.prepareStatement("insert into test values(?,?)"); 63 psGet = conn.prepareStatement("select body from test where id=?"); 64 65 for (long i = 0; i < 65560; i++) { 66 67 if (i % 10 == 0) 68 buff.append(" "); 69 else 70 buff.append("x"); 71 72 if (i % 10000 == 0) 74 System.out.println("... " + i ); 75 76 if (buff.length() > 65525) { 78 79 System.out.println("i = " + i + ", testing length: " + buff.length()); 80 81 longText = buff.toString(); 82 setBody(i, longText); 84 85 String res = getBody(i); 87 if (!res.equals(longText)) { 88 System.out.println("FAIL -- string fetched is incorrect, length is " 89 + buff.length() + ", expecting string: " + longText 90 + ", instead got the following: " + res); 91 break; 92 } 93 } 94 } 95 96 conn.close(); 97 98 } catch (SQLException e) { 99 dumpSQLExceptions(e); 100 } catch (Throwable e) { 101 System.out.println("FAIL -- unexpected exception:" + e.toString()); 102 } 103 104 System.out.println("Test longStringColumn finished"); 105 106 } 107 108 private static void setBody(long key, String body) { 109 110 try { 111 psSet.setLong(1, key); 112 psSet.setString(2, body); 113 psSet.executeUpdate(); 114 115 } catch (SQLException ex) { 116 ex.printStackTrace(); 117 118 System.out.println("FAIL -- unexpected exception"); 119 System.exit(-1); 120 } 121 } 122 123 private static String getBody(long key) { 124 125 String result="NO RESULT"; 126 127 try { 128 psGet.setLong(1, key); 129 ResultSet rs = psGet.executeQuery(); 130 131 if (rs.next()) 132 result = rs.getString(1); 133 134 } catch (SQLException ex) { 135 ex.printStackTrace(); 136 } 137 138 return result; 139 } 140 141 static private void dumpSQLExceptions (SQLException se) { 142 System.out.println("FAIL -- unexpected exception: " + se.toString()); 143 while (se != null) { 144 System.out.print("SQLSTATE("+se.getSQLState()+"):"); 145 se = se.getNextException(); 146 } 147 } 148 149 } 150 | Popular Tags |