gpt4 book ai didi

java - 是什么导致了这个 SQLException?

转载 作者:行者123 更新时间:2023-12-01 07:10:27 24 4
gpt4 key购买 nike

我收到以下错误:

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 '' at line 1.

尝试运行以下代码时:

String sql = "INSERT INTO `tutors`.`appointments`"
+ "(`tutorID`, `tuteeName`, `tuteeEmail`, `time`, `date`)"
+ ("VALUES(?, ?, ?, ?, ?");
try {
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1, working.get(0).getTutorID());
ps.setString(2, tuteeName);
ps.setString(3, tuteeEmail);
ps.setDate(4, date);
ps.setTime(5, time);
ps.executeUpdate();

异常所指的 ' ' 是由什么产生的?我刚刚学习在 java 中使用 SQL,所以我确信这只是一个愚蠢的语法错误......

最佳答案

您没有关闭 VALUES 括号:

 String sql = "INSERT INTO `tutors`.`appointments`"
+ " (`tutorID`, `tuteeName`, `tuteeEmail`, `time`, `date`)"
+ ("VALUES(?, ?, ?, ?, ?)");

关于java - 是什么导致了这个 SQLException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15425869/

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