I've a table on PostgreSQL like this:
I want to running another Java .class by the content inside the DATA table.
If the content written FIT1, i want to run the FIT1.class;
So do if the content written FIT2, i want to run the FIT2.class; etc.
I only got my code below, and i think it's not work bcs when it tried to get the content, it got all the contents. So the IF function cant work.
Base on the table, i want to running all the process (7 data).
Is there any solution to fix the code?
package fit;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class FIT {
public static void main( String args[] )
{
Connection c = null;
Statement stmt = null;
try {
Class.forName("org.postgresql.Driver");
c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/FIT","admin", "admin");
c.setAutoCommit(false);
System.out.println("Opened database successfully");
stmt = c.createStatement();
ResultSet rs = stmt.executeQuery( "SELECT * FROM DATA;" );
while ( rs.next() ) {
String data = rs.getString("data");
System.out.println( "Data = " + data );
System.out.println();
if (data.equals("FIT1")){
FIT1.main(args);
}
else if (data.equals("FIT2")){
FIT2.main(args);
}
else{
}
}
rs.close();
stmt.close();
c.close();
} catch ( Exception e ) {
System.err.println( e.getClass().getName()+": "+ e.getMessage() );
System.exit(0);
}
System.out.println("Operation done successfully");
}
}