Kartik Singh
Kartik Singh

Reputation: 43

Updated: Problem with executing SQL query from Java

Updated: so as per the suggestions i changed all the column name to strings and added prepared statements-

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/minor","root","alphabet")) {
            Statement st = conn.createStatement();
            PreparedStatement stmt= conn.prepareStatement("select * FROM ? where name=? ;");
            PreparedStatement stmt2= conn.prepareStatement("select * FROM ? where name=? ;");
            stmt.setString(1, day_1);
            stmt.setString(2, faculty1);
            stmt2.setString(1,day_1);
            stmt2.setString(2, faculty2);
            ResultSet rs=stmt.executeQuery();
            ResultSet rs1= stmt.executeQuery();

The day and faculty is retrieved from input screen, the queries work just fine in mysql workbench but the 'select' keyword goes missing when i try to run it from Java, see the following error- No select keyword The faculty1, faculty2 is retrieved from the following- retrieve The database looks like this- database

Upvotes: 0

Views: 586

Answers (1)

usr999
usr999

Reputation: 156

  1. I would recommend to use PreparedStatement instead of Statement, then at least you can bind your variables;
  2. You query select from time_interval from day_selected is not correct, I don't think that it will execute anywhere, you need to have something between select and from, and not two from in one statement.

Upvotes: 1

Related Questions