1 import java.util.*;
2 import java.io.*;
3 import java.sql.*;
4 
5 public class BatchTest extends PgpoolTest {
6     public String [] batchSqls = new String[] {
7 	"INSERT INTO batch VALUES (1)",
8 	"INSERT INTO batch VALUES (1)",
9 	"INSERT INTO batch VALUES (1)",
10 	"INSERT INTO batch VALUES (1)",
11 	"INSERT INTO batch VALUES (1)",
12 	"INSERT INTO batch VALUES (1)",
13 	"INSERT INTO batch VALUES (1)",
14 	"INSERT INTO batch VALUES (1)",
15 	"INSERT INTO batch VALUES (1)",
16 	"INSERT INTO batch VALUES (1)",
17 	"INSERT INTO batch VALUES (1)",
18     };
19 
do_test()20     public void do_test() throws SQLException {
21         connection.setAutoCommit(false);
22 
23         Statement stmt = null;
24         ResultSet rs = null;
25 
26         try {
27             try {
28                 stmt = connection.createStatement();
29                 for(int i=0; i<batchSqls.length; i++) {
30                     stmt.addBatch(batchSqls[i]);
31                 }
32                 int [] r = stmt.executeBatch();
33 
34                 connection.commit();
35 		stmt.close();
36 
37 		stmt = connection.createStatement();
38 		rs = stmt.executeQuery("SELECT count(*) FROM batch");
39 		rs.next();
40 		logwriter.println(rs.getInt(1));
41                 connection.commit();
42             } finally {
43                 if(rs != null) rs.close();
44                 if(stmt != null) stmt.close();
45             }
46         } finally {
47             connection.close();
48 	    logwriter.close();
49         }
50     }
51 
getTestName()52     public String getTestName() {
53 	return "batch";
54     }
55 }
56