gpt4 book ai didi

java - 在 java 中执行 mysql 行时出错

转载 作者:行者123 更新时间:2023-11-29 00:25:46 25 4
gpt4 key购买 nike

这是我的代码

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:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Samiee' at line 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)

请问是什么原因?

最佳答案

将您的 SQL 行更改为以下,您缺少 ' 字符...

SELECT user_name FROM user where person_name= '"+Dillingdoctor+"' 

关于java - 在 java 中执行 mysql 行时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19003400/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com