【发布时间】:2016-12-17 12:50:30
【问题描述】:
我正在尝试在我的表中进行简单的插入,但我的程序说我有一个 SQL 语法错误。有什么想法吗?
SQL 代码
CREATE TABLE ticket (
start_time DATETIME NOT NULL,
end_time DATETIME NOT NULL,
seat VARCHAR(50) NOT NULL,
sep VARCHAR(50) NOT NULL,
price INT(50) NOT NULL,
foroom VARCHAR(50) NOT NULL,
printer INT(15) NOT NULL,
PRIMARY KEY (seat)
);
JAVA 代码
try
{
System.out.println("Attempting to connect...\n");
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/baseis?autoReconnect=true&useSSL=false","root","");
System.out.println("Connection Succesful!!!");
String sql = "INSERT INTO ticket (start_time)" + " VALUES (?)";
PreparedStatement prepared = connection.prepareStatement(sql);
prepared.setString(1,"2016-07-17 19:00:00");
prepared.executeUpdate(sql);
}
catch(SQLException error)
{
System.out.println("Error: " + error.getMessage());
}
错误
Error: 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
【问题讨论】:
标签: java mysql sql-server jdbc insert