You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near #39;?#39; at line 1(您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以了解在“?附近使用的正确语法.在第 1 行) - IT屋-程序员软
问题描述
我正在使用 Java 和 JDBC 制作库存系统.我在查询表时遇到了这个错误.
I'm making an inventory system using Java and JDBC. I have got this error some how when querying a table.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 你的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以了解在?"附近使用的正确语法.在第 1 行
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?' at line 1
下面是代码
public static void SearchUser() throws SQLException{
String ordersquery = "SELECT * FROM orders WHERE submittedBy = ?";
User userDetails = UserController.getUserDetails(username);//gets the details from user tables
if (userDetails != null){
System.out.println("----Menu----");
System.out.println();
System.out.println("1. View Orders Made By This User");
System.out.println("2. View Most Expensive Parts Currently Taken Out By This User");
System.out.println();
System.out.println("9. Go Back To Main Menu");
choice = input.nextLine();
if (choice.equals("1")){
try (
PreparedStatement stmt2 = conn.prepareStatement(ordersquery);
){
stmt2.setInt(1, userDetails.getUserId());
ResultSet rsOrders = stmt2.executeQuery(ordersquery);
if (rsOrders != null){
while (rsOrders.next()){
Order orderDetails = new Order(rsOrders.getInt("orderId"), userDetails.getUserId(), rsOrders.getInt("totalItems"), rsOrders.getInt("totalPrice"));
System.out.println("-------------------------------------");
Order.print(orderDetails);
}
}
}catch (SQLException e){
System.err.println(e);
}
}else if (choice.equals("2")){
}
}
}
推荐答案
ResultSet rsOrders = stmt2.executeQuery(ordersquery);
stmt2 是你的 sql 查询那么你为什么要传递 ordersquery 将你的代码更改为下面的代码
stmt2 is you sql query then why are you passing ordersquery change your code to below code
ResultSet rsOrders = stmt2.executeQuery();
这篇关于您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以了解在“?"附近使用的正确语法.在第 1 行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册,以了解在“?"附近使用的正确语法.在第 1 行
基础教程推荐
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
