-1

I've a table on PostgreSQL like this:

table

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");
     }
}
NWD
  • 77
  • 2
  • 10
  • I'm not sure what the exact problem is but for string comparision better use `String.equalsIgnoreCase` instead of `==` – Pons Mar 20 '17 at 07:21
  • Possible duplicate of [How do I compare strings in Java?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Seelenvirtuose Mar 20 '17 at 07:24

1 Answers1

1

instead check data == "FIT1" use equals

try this block code:

if (data.equals("FIT1")){
    FIT1.main(args);
}

else if (data.equals("FIT2")){
    FIT2.main(args);
}
Piotr Rogowski
  • 3,642
  • 19
  • 24
  • Oh ok i should use data.equals("FIT1"). But it still not solving the problem, bcs i need to run every process by every content inside the table. If there was 7data, i need to run all the 7 process... – NWD Mar 20 '17 at 07:29