这是我的代码
String Dillingdoctor = driver.findElement(By.id("txtProviderName")).getAttribute("value");
ResultSet res2 = st.executeQuery("SELECT user_name FROM user where person_name= "+Dillingdoctor+" ");
res2.next();
String Billing_Doctor = res2.getString(1);
System.out.println(Billing_Doctor);
我有这个错误:
Exception in thread "main"
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 靠近'Samiee'的第1行
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
at com.mysql.jdbc.Util.getInstance(Util.java:382)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3593)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3525)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1986)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2140)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2620)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2570)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1474)
at login.Verification.main(Verification.java:168)
我可以知道是什么原因吗?
答案 0 :(得分:1)
将您的SQL行更改为以下内容,您缺少'characters ...
SELECT user_name FROM user where person_name= '"+Dillingdoctor+"'