1 package nmp.dbms.util;
2
3 import java.io.*;
4 import java.sql.*;
5 import nmp.dbms.JDBC.*;
6
7 public class InterDB {
8 public static void main( String[] args)
9 throws IOException{
10 if( args == null || ( args.length != 3 && args.length != 4)) {
11 System.err.println( "Usage:\n InterDB url userName userPwd [driver]");
12 return;
13 }
14
15 try {
16 Jdbc_Sql sql = null;
17 if( args.length == 3)
18 sql = new Jdbc_Sql( "sun.jdbc.odbc.JdbcOdbcDriver", args[0], args[1], args[2]);
19 else
20 sql = new Jdbc_Sql( args[3], args[0], args[1], args[2]);
21
22 doit( sql);
23
24 sql.closeAll();
25 }
26 catch( Exception e) {
27 PrintWriter pw;
28 String name = args[0].substring( args[0].lastIndexOf( ':') + 1);
29 try {
30 pw = new PrintWriter( new FileWriter( "ERR_" + name + ".log", true));
31 }
32 catch( FileNotFoundException e0) {
33 pw = new PrintWriter( new FileWriter( "ERR_" + name + ".log"));
34 }
35 e.printStackTrace( pw);
36 pw.println();
37 pw.flush();
38 }
39 }
40
41 static void doit( Jdbc_Sql sql)
42 throws IOException {
43 BufferedReader reader = new BufferedReader( new InputStreamReader( System.in));
44 for( ; ; ) {
45 System.out.print( "? ");
46 System.out.flush();
47 String line = reader.readLine();
48 line = line.trim();
49 if( line.equals( "quit"))
50 break;
51 try {
52 System.out.println( "Native SQL : " + sql.nativeSQL( line));
53 if( line.startsWith( "select"))
54 Utilities.displayResultSet( System.out, sql.executeQuery( line));
55 else
56 System.out.println( sql.executeUpdate( line) + " rows modified");
57 }
58 catch( SQLException e) {
59 e.printStackTrace();
60 }
61 }
62 }
63
64 }
65
This page was automatically generated by Maven