1 30 31 32 package org.hsqldb.test; 33 34 import java.sql.Connection ; 35 import java.sql.DriverManager ; 36 import java.sql.PreparedStatement ; 37 import java.sql.ResultSet ; 38 import java.sql.SQLException ; 39 import java.sql.Statement ; 40 41 import junit.framework.Test; 42 import junit.framework.TestCase; 43 import junit.framework.TestSuite; 44 45 51 public class TestQuotes extends TestCase { 52 53 private static final String CREATETABLE = 54 "create table quotetest (test varchar)"; 55 private static final String DELETE = "delete from quotetest"; 56 private static final String TESTSTRING = 57 "insert into quotetest (test) values (?)"; 58 private static final String NOQUOTES = "the house of the dog of kevin"; 59 private static final String QUOTES = "kevin's dog's house"; 60 private static final String RESULT = "select * from quotetest"; 61 62 public TestQuotes(String testName) { 63 super(testName); 64 } 65 66 69 public static Test suite() { 70 return new TestSuite(org.hsqldb.test.TestQuotes.class); 71 } 72 73 public void testSetString() { 74 75 Connection connection = null; 76 Statement statement = null; 77 PreparedStatement pStatement = null; 78 ResultSet rs1 = null; 79 ResultSet rs2 = null; 80 81 try { 82 DriverManager.registerDriver(new org.hsqldb.jdbcDriver()); 83 84 connection = DriverManager.getConnection("jdbc:hsqldb:.", "sa", 85 ""); 86 statement = connection.createStatement(); 87 88 statement.executeUpdate(CREATETABLE); 89 90 pStatement = connection.prepareStatement(TESTSTRING); 91 92 pStatement.setString(1, NOQUOTES); 93 pStatement.executeUpdate(); 94 95 rs1 = statement.executeQuery(RESULT); 96 97 rs1.next(); 98 99 String result1 = rs1.getString(1); 100 101 assertTrue("result1 is -" + result1 + "- not -" + NOQUOTES + "-", 102 NOQUOTES.equals(result1)); 103 statement.executeUpdate(DELETE); 104 pStatement.setString(1, QUOTES); 105 pStatement.executeUpdate(); 106 107 rs2 = statement.executeQuery(RESULT); 108 109 rs2.next(); 110 111 String result2 = rs2.getString(1); 112 113 assertTrue("result2 is " + result2, QUOTES.equals(result2)); 114 } catch (SQLException sqle) { 115 fail(sqle.getMessage()); 116 } finally { 117 if (rs2 != null) { 118 try { 119 rs2.close(); 120 } catch (SQLException sqle) { 121 sqle.printStackTrace(); 122 } 123 } 124 125 if (rs1 != null) { 126 try { 127 rs1.close(); 128 } catch (SQLException sqle) { 129 sqle.printStackTrace(); 130 } 131 } 132 133 if (statement != null) { 134 try { 135 statement.close(); 136 } catch (SQLException sqle) { 137 sqle.printStackTrace(); 138 } 139 } 140 141 if (pStatement != null) { 142 try { 143 pStatement.close(); 144 } catch (SQLException sqle) { 145 sqle.printStackTrace(); 146 } 147 } 148 149 if (connection != null) { 150 try { 151 connection.close(); 152 } catch (SQLException sqle) { 153 sqle.printStackTrace(); 154 } 155 } 156 } 157 } 158 } 159 | Popular Tags |