1 pjaol 1.1 package com.javaunderground.jdbc;
2
3 /**
4 * Title:
5 * Description:
6 * Copyright: Copyright (c) 2001
7 * Company:
8 * @author
9 * @version 1.0
10 */
11
12 import java.sql.*;
13 import java.util.*;
14
15 public class tester {
16
17 public tester() {
18 }
19
20 public static void main(String[] args) {
21 System.out.println("Hello World");
22 pjaol 1.1 String[] a=new String[0];
23
24
25 SqlFormatter formatter = new OracleSqlFormatter();
26 Object o=new java.sql.Date(new java.util.Date().getTime());
27 try{
28 System.out.println("date="+formatter.format(o));
29 o=new Long(198);
30 System.out.println("Long="+formatter.format(o));
31 o=new Boolean(true);
32 System.out.println("Boolean="+formatter.format(o));
33 }catch(SQLException e){
34 e.printStackTrace();
35 }
36
37 //this goes in static debug class once, not individual classes
38 StatementFactory.setDefaultDebug(DebugLevel.VERBOSE);
39 StatementFactory.setDefaultFormatter(new OracleSqlFormatter());
40
41 //test debuggable
42 java.sql.Connection con = null;
43 pjaol 1.1 java.sql.PreparedStatement ps = null;
44 java.sql.ResultSet rs = null;
45
46 String databaseURL = "jdbc:interbase://10.0.0.1/opt/interbase/examples/employee.gdb";
47 System.out.println(databaseURL);
48 String user = "sysdba";
49 String password = "masterkey";
50 String driverName = "interbase.interclient.Driver";
51
52 try{
53 Class.forName("interbase.interclient.Driver");
54 System.out.println("interbase.interclient.Driver");
55 java.util.Properties props = new java.util.Properties();
56 props.put ("user", user);
57 props.put ("password", password);
58 System.out.println("user = " + props.get("user"));
59 con = DriverManager.getConnection(databaseURL,props);
60 System.out.println ("Connection established.");
61
62 String sql = "select * from employee where last_name = ? or first_name = 'john?'";
63 ps = StatementFactory.getStatement(con,sql);
64 pjaol 1.1 ps.setString(1,"Montgomery");
65 System.out.println(ps.toString());
66 rs = ps.executeQuery();
67 while(rs.next()){
68 System.out.println("employee name = " + rs.getString("last_name"));
69 }
70
71 }catch(java.lang.ClassNotFoundException e){
72 e.printStackTrace();
73 }catch(java.sql.SQLException se){
74 se.printStackTrace();
75 }
76 finally{
77 try{
78 if(rs != null){rs.close();}
79 if(ps != null){ps.close();}
80 if(!con.isClosed()) con.close();
81 }catch(SQLException e){
82 e.printStackTrace();
83 }
84 }
85 pjaol 1.1
86
87
88 }
89 }
|