1 24 25 package org.objectweb.cjdbc.scenario.raidb1.driver; 26 27 import java.sql.Connection ; 28 import java.sql.PreparedStatement ; 29 import java.sql.ResultSet ; 30 import java.util.Properties ; 31 32 import org.objectweb.cjdbc.driver.ControllerInfo; 33 import org.objectweb.cjdbc.scenario.templates.Raidb1Template; 34 35 40 public class PreparedStatementSetStringScenario extends Raidb1Template 41 { 42 47 public void testSetString() throws Exception 48 { 49 Properties props = new Properties (); 50 props.put("user", "user"); 51 props.put("password", ""); 52 props.put("escapeBackslash", "false"); 53 props.put("escapeSingleQuote", "true"); 54 55 Connection con = getCJDBCConnection( 56 new ControllerInfo[]{new ControllerInfo("localhost", 25322)}, "myDB", 57 props); 58 59 String mygeorge = "" + 'G' + 'e' + '\'' + 'o' + 'r' + '\\' + 'g' + '\\' 60 + 'e'; 61 String statement = "INSERT INTO ADDRESS VALUES(50,?,'Fuller','534 - 20th Ave.','Olten')"; 62 PreparedStatement ps = con.prepareStatement(statement); 63 ps.setString(1, mygeorge); 64 ps.setEscapeProcessing(true); 65 ps.executeUpdate(); 66 67 PreparedStatement ps2 = con 68 .prepareStatement("Select * from ADDRESS where id=?"); 69 ps2.setString(1, "50"); 70 ResultSet rs = ps2.executeQuery(); 71 assertTrue("Empty result set", rs.next()); 72 String george = rs.getString("firstname"); 73 assertEquals("Wrong value for george (was :" + george + " )", george, 74 mygeorge); 75 } 76 } | Popular Tags |