import java.sql.*;

public class DB {
  public static void main(String[] args) throws Exception {
    if (args.length != 1 || "".equals(args[0].trim())) {
      System.err.println("Error: <SQL>");
      System.exit(1);
    }
    String sql = args[0];
    Connection conn = null;
    try {
      String url = "jdbc:derby:/home/hashiwa/java/AccountBook/db_production;create=true;user=test;password=test";
      conn = DriverManager.getConnection(url);
      Statement stat = conn.createStatement();
      ResultSet result = stat.executeQuery(sql);
      //ResultSet result = stat.executeQuery("select t.tablename, t.tabletype, s.schemaname from sys.systables as t join sys.sysschemas as s on t.schemaid = s.schemaid");
      while (result.next()) {
        System.out.println(createRowString(result));
      }
    } finally {
      if (conn != null) conn.close();
    }
  }

  private static String createRowString(ResultSet result) throws SQLException {
    ResultSetMetaData metadata = result.getMetaData();
    int columnCount = metadata.getColumnCount();
    StringBuilder buf = new StringBuilder();
    for (int i=1 ; i<=columnCount ; i++) {
      String s = result.getString(i);
      buf.append(s);
      buf.append('\t');
    }
    return buf.toString().trim();
  }
}

@@ -31,16 +31,148 @@
 ss DB %7B%0A
+  private static final  String URL = %22jdbc:derby:/home/hashiwa/java/AccountBook/db_production;create=true;user=test;password=test%22;%0A
   public
@@ -374,16 +374,23 @@
  args%5B0%5D
+.trim()
 ;%0A    Co
@@ -431,212 +431,503 @@
     
-String url = %22jdbc:derby:/home/hashiwa/java/AccountBook/db_production;create=true;user=test;password=
+conn = DriverManager.getConnection(URL);%0A      Statement stat = conn.createStatement();%0A      if (isSelectStatement(sql)) %7B%0A        doSelect(stat, sql);%0A      %7D else %7B%0A        doUpda
 te
+(
 st
-%22;%0A      
+at, sql);%0A      %7D%0A    %7D finally %7B%0A      if (
 conn 
+!
 = 
-DriverManager.getConnection(url);%0A      Statement stat = conn.createStatement();%0A  
+null) conn.close();%0A    %7D%0A  %7D%0A%0A  private static boolean isSelectStatement(String sql) %7B%0A    String type = sql.split(%22 %22)%5B0%5D.toLowerCase();%0A    return %22select%22.equals(type);%0A  %7D%0A%0A  private static void doSelect(Statement stat, String sql) throws Exception %7B%0A
     
@@ -965,26 +965,24 @@
 Query(sql);%0A
-  
     //Result
@@ -1142,18 +1142,16 @@
 %22);%0A    
- 
- 
 while (r
@@ -1162,26 +1162,24 @@
 t.next()) %7B%0A
-  
       System
@@ -1225,71 +1225,182 @@
     
+%7D%0A
   %7D%0A
+%0A
   
-  %7D finally %7B%0A      if (conn != null) conn.close();%0A    %7D
+private static void doUpdate(Statement stat, String sql) throws Exception %7B%0A    int rowCount = stat.executeUpdate(sql);%0A    System.out.println(%22rows = %22 + rowCount);
 %0A  %7D

enable to delete