import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

// TODO: when ran via CLI, connect to database, open inSocket and outSocket, wait for start-message, send greetings to home, wait for response ... do stuff

public class JDBCResponder {

    public static void main(String[] args) {

        String query = null;
        String dbConnStr = null;
        String dbUname = null;
        String dbPassw = null;

        try {

            Class.forName("oracle.jdbc.driver.OracleDriver");

        } catch(ClassNotFoundException e) {

            System.out.println("JDBCResponder: Oracle JDBC Driver not found!");
            e.printStackTrace();
            System.exit(0);

        }

        System.out.println("JDBCResponder: Oracle JDBC Driver registered!");

        try {

            dbConnStr = args[0];
            dbPassw = args[1].toString();

        } catch(Exception e) {

            e.printStackTrace();
            System.exit(0);

        }

        System.out.println("JDBCResponder: Executing query.");
        ResultSet rs = null;
        try {

            Connection connection = DriverManager.getConnection(dbConnStr, dbUname, dbPassw);

            try {

                Statement stmt = connection.createStatement();
                // Query is provided as command line argument.
                System.out.println("QUERY : " + query);
                rs = stmt.executeQuery(query);

            } catch(SQLException e) {

                System.out.println("JDBCResponder: SQL error!");
                e.printStackTrace();

            }

        } catch(Exception e) {

            System.out.println("JDBCResponder: Error!");
            e.printStackTrace();

        }

        try {

            while(rs.next()) {

                String yearName = rs.getString("YEAR");
                System.out.println(yearName);

            }

        } catch(SQLException e) {

            System.out.println("SQLException!");
            e.printStackTrace();

        }
    }
}
@@ -915,34 +915,54 @@
   db
-Passw = args%5B1%5D.toString()
+Uname = args%5B1%5D;%0A            dbPassw = args%5B2%5D
 ;%0A%0A 
@@ -1077,106 +1077,160 @@
     
-System.out.println(%22JDBCResponder: Executing query.%22);%0A        ResultSet rs = null;%0A        try %7B%0A
+ResultSet rs = null;%0A        try %7B%0A%0A            // %22(DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST=toldb.oulu.fi) (PORT=1521))(CONNECT_DATA=(SID=toldb11)))%22
 %0A   
@@ -1332,32 +1332,78 @@
          try %7B%0A%0A
+                query = %22SELECT * FROM YEAR%22;%0A
                 
@@ -1453,71 +1453,8 @@
 ();%0A
-                // Query is provided as command line argument.%0A
     
@@ -1549,24 +1549,142 @@
 ry(query);%0A%0A
+                while(rs.next()) %7B%0A%0A                    System.out.println(rs.getString(%22YEAR%22));%0A%0A                %7D%0A%0A
             
@@ -1955,302 +1955,8 @@
 );%0A%0A
-        %7D%0A%0A        try %7B%0A%0A            while(rs.next()) %7B%0A%0A                String yearName = rs.getString(%22YEAR%22);%0A                System.out.println(yearName);%0A%0A            %7D%0A%0A        %7D catch(SQLException e) %7B%0A%0A            System.out.println(%22SQLException!%22);%0A            e.printStackTrace();%0A%0A
     

read db credentials from argument list