01: package com.bostechcorp.cbesb.runtime.jdbc;
02:
03: import junit.framework.TestCase;
04: import java.sql.ResultSet;
05: import java.sql.ResultSetMetaData;
06:
07: public class TestJDBC extends TestCase {
08:
09: public void test() throws Throwable {
10: JdbcSessionFactory jsf = new JdbcSessionFactory();
11:
12: jsf
13: .setDriverName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
14: jsf
15: .setUrl("jdbc:microsoft:sqlserver://bt-rd02:1433;database=pubs");
16: jsf.setUser("testuser");
17: jsf.setPassword("bostech1");
18: jsf.setAutoCommit(true);
19: jsf.setConnectionRetries(3);
20: jsf.setConnectionInterval(3000);
21:
22: JdbcSession session = jsf.getNewSession();
23:
24: JdbcStatement statement = new JdbcStatement();
25: statement
26: .setSqlStatement("select stor_id, stor_name, stor_address, city, state, zip from stores");
27:
28: session.executeStatement(statement);
29:
30: ResultSet rs = session.getResultSet();
31:
32: rs.last();
33: int rowCnt = rs.getRow();
34: System.out.println("Number of rows selected = " + rowCnt);
35: System.out.flush();
36:
37: // rs.first();
38: // ResultSetMetaData rsmd = rs.getMetaData();
39:
40: session.close();
41:
42: session = jsf.getNewSession();
43:
44: statement = new JdbcStatement();
45: statement
46: .setSqlStatement("select stor_id, stor_name, stor_address, city, state, zip from stores where state = ?");
47: JdbcVar var = new JdbcVar(JdbcVar.MODE_IN, java.sql.Types.CHAR,
48: "CA");
49: statement.addBindVar(var);
50:
51: session.executeStatement(statement);
52:
53: rs = session.getResultSet();
54:
55: rs.last();
56: rowCnt = rs.getRow();
57: System.out.println("Number of rows selected = " + rowCnt);
58: }
59:
60: }
|