使用jdbc在mysql中执行查询时出错

时间:2016-03-30 14:53:02

标签: java jdbc

我想使用jdbc程序对表执行查询。程序提示用户输入字符串并检索表数据取决于字符串。我的代码在这里

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);

但我在运行时遇到这样的错误

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)

任何人都可以提供解决方案。提前谢谢

1 个答案:

答案 0 :(得分:0)

它可能对你有所帮助  检查此代码

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