33 */
44package smallsql .tools ;
55
6- import java .io .*;
6+ import smallsql .database .SSDriver ;
7+
8+ import javax .swing .*;
9+ import java .io .BufferedReader ;
10+ import java .io .IOException ;
11+ import java .io .InputStreamReader ;
712import java .sql .*;
813import java .util .Properties ;
914
10- import javax .swing .JOptionPane ;
11-
12- import smallsql .database .*;
13-
14-
1515/**
1616 * @author Volker Berlin
1717 */
1818public class CommandLine {
1919
20-
2120 public static void main (String [] args ) throws Exception {
2221 System .out .println ("SmallSQL Database command line tool\n " );
23- Connection con = new SSDriver ().connect ("jdbc:smallsql" , new Properties ());
22+ Connection con = new SSDriver ().connect ("jdbc:smallsql:db1?create=true " , new Properties ());
2423 Statement st = con .createStatement ();
25- if (args .length > 0 ) {
24+ if (args .length > 0 ) {
2625 con .setCatalog (args [0 ]);
2726 }
28- System .out .println ("\t Version: " + con .getMetaData ().getDatabaseProductVersion ());
29- System .out .println ("\t Current database: " + con .getCatalog ());
27+ System .out .println ("\t Version: " + con .getMetaData ().getDatabaseProductVersion ());
28+ System .out .println ("\t Current database: " + con .getCatalog ());
3029 System .out .println ();
3130 System .out .println ("\t Use the USE command to change the database context." );
3231 System .out .println ("\t Type 2 times ENTER to execute any SQL command." );
33-
32+
3433 StringBuffer command = new StringBuffer ();
3534 BufferedReader input = new BufferedReader (new InputStreamReader (System .in ));
36- while (true ){
35+ while (true ) {
3736 try {
3837 String line ;
39- try {
38+ try {
4039 line = input .readLine ();
41- }catch (IOException ex ){
40+ } catch (IOException ex ) {
4241 ex .printStackTrace ();
43- JOptionPane .showMessageDialog ( null , "You need to start the command line of the \n SmallSQL Database with a console window:\n \n java -jar smallsql.jar\n \n " + ex , "Fatal Error" , JOptionPane .OK_OPTION );
42+ JOptionPane .showMessageDialog (null , "You need to start the command line of the \n SmallSQL Database with a console window:\n \n java -jar smallsql.jar\n \n " + ex , "Fatal Error" , JOptionPane .OK_OPTION );
4443 return ;
4544 }
46- if (line == null ){
45+ if (line == null ) {
4746 return ; //end of program
4847 }
49- if (line .length () == 0 && command .length () > 0 ){
48+ if (line .length () == 0 && command .length () > 0 ) {
5049 boolean isRS = st .execute (command .toString ());
51- if (isRS ){
50+ if (isRS ) {
5251 printRS (st .getResultSet ());
5352 }
5453 command .setLength (0 );
@@ -59,20 +58,20 @@ public static void main(String[] args) throws Exception {
5958 e .printStackTrace ();
6059 }
6160 }
62-
61+
6362 }
64-
63+
6564
6665 private static void printRS (ResultSet rs ) throws SQLException {
6766 ResultSetMetaData md = rs .getMetaData ();
6867 int count = md .getColumnCount ();
69- for (int i = 1 ; i <= count ; i ++){
68+ for (int i = 1 ; i <= count ; i ++) {
7069 System .out .print (md .getColumnLabel (i ));
7170 System .out .print ('\t' );
7271 }
7372 System .out .println ();
74- while (rs .next ()){
75- for (int i = 1 ; i <= count ; i ++){
73+ while (rs .next ()) {
74+ for (int i = 1 ; i <= count ; i ++) {
7675 System .out .print (rs .getObject (i ));
7776 System .out .print ('\t' );
7877 }
0 commit comments