简体   繁体   中英

Error while executing query in mysql using jdbc

I want to execute a query on a table using jdbc program.The program prompt the user to enter string and retrieve the table data depends on string. my code is here

Class.forName("com.mysql.jdbc.Driver");
       Scanner sc=new Scanner(System.in);
         System.out.println(" enter string name");
      String s=sc.next();
 Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/s","srinu","srinu");     
         Statement st=con.createStatement();
 ResultSet rs=st.executeQuery("select * from india where english="+s);

but i am getting error at run time like this

java.sql.SQLException: Unknown column 'flag' in 'where clause'
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2975)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1695)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:3020)
        at com.mysql.jdbc.Connection.execSQL(Connection.java:2949)
        at com.mysql.jdbc.Statement.executeQuery(Statement.java:959)
        at Test.main(Test.java:20)

can any one provide me solution.thanks in advance

It may help you check this code

ResultSet rs=st.executeQuery("select * from india where english=' "+s+" ' ");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM