1 24 25 package org.objectweb.cjdbc.scenario.raidb1.driver; 26 27 import java.io.File ; 28 import java.sql.Blob ; 29 import java.sql.Connection ; 30 import java.sql.PreparedStatement ; 31 32 import org.objectweb.cjdbc.scenario.templates.Raidb1Template; 33 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility; 34 35 40 public class PreparedStatementScenario extends Raidb1Template 41 { 42 43 private static final int N = 50; 45 46 51 public void testLoopCreateStatement() throws Exception 52 { 53 Connection con = getCJDBCConnection(); 54 String tableName = "testblob" + System.currentTimeMillis(); 55 PreparedStatement stmt = null; 56 for (int i = 0; i < N; i++) 57 { 58 stmt = con.prepareStatement("create table " + tableName + i 59 + " (id INTEGER,name VARCHAR)"); 60 stmt.executeUpdate(); 61 } 62 } 63 64 69 public void testLoopCreateStatementAndClose() throws Exception 70 { 71 Connection con = getCJDBCConnection(); 72 String tableName = "testblob" + System.currentTimeMillis(); 73 for (int i = 0; i < N; i++) 74 { 75 PreparedStatement stmt = null; 76 stmt = con.prepareStatement("create table " + tableName + i 77 + " (id INTEGER,name VARCHAR)"); 78 stmt.executeUpdate(); 79 stmt.close(); 80 } 81 } 82 83 88 public void testLoopInsertBlobStatementAndClose() throws Exception 89 { 90 String imageFile = "/image/logo-noel.jpg"; 91 File fis = new File (getClass().getResource(imageFile).getFile()); 92 Connection con = getCJDBCConnection(); 93 94 String tableName = "testblob" + System.currentTimeMillis(); 95 PreparedStatement stmt = con.prepareStatement("create table " + tableName 96 + " (id INTEGER,name VARCHAR)"); 97 98 stmt.executeUpdate(); 99 stmt.close(); 100 101 String query = "Insert into " + tableName + " values(1,?)"; 102 PreparedStatement ps1 = con.prepareStatement(query); 103 Blob bob = new org.objectweb.cjdbc.driver.Blob(ScenarioUtility 104 .readBinary(fis)); 105 ps1.setBlob(1, bob); 106 ps1.executeUpdate(); 107 ps1.close(); 108 } 109 110 } | Popular Tags |