Skip to content

Commit f3f9a56

Browse files
committed
IT WORKS!
- Test SQL statements: CREATE TABLE a2 (pr numeric IDENTITY,i int) INSERT INTO a2 (pr,i) VALUES (1111,22) SELECT * FROM a2
1 parent 9c8fe17 commit f3f9a56

File tree

3 files changed

+26
-209
lines changed

3 files changed

+26
-209
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,6 @@ Temporary Items
5353
.settings
5454
.classpath
5555
.project
56+
57+
# DB file
58+
db1

src/main/java/smallsql/database/language/Language_it.java

Lines changed: 0 additions & 185 deletions
This file was deleted.

src/main/java/smallsql/tools/CommandLine.java

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,51 @@
33
*/
44
package 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;
712
import java.sql.*;
813
import java.util.Properties;
914

10-
import javax.swing.JOptionPane;
11-
12-
import smallsql.database.*;
13-
14-
1515
/**
1616
* @author Volker Berlin
1717
*/
1818
public 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("\tVersion: "+con.getMetaData().getDatabaseProductVersion());
29-
System.out.println("\tCurrent database: "+con.getCatalog());
27+
System.out.println("\tVersion: " + con.getMetaData().getDatabaseProductVersion());
28+
System.out.println("\tCurrent database: " + con.getCatalog());
3029
System.out.println();
3130
System.out.println("\tUse the USE command to change the database context.");
3231
System.out.println("\tType 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 \nSmallSQL 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 \nSmallSQL 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

Comments
 (0)