这是我的代码段,
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
public class Delete
{
public static void main(String args[])
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("mysql:jdbc://localhost:3306/raja","root","459805");
Statement stmt=con.createStatement();
int count=stmt.executeUpdate("DELETE GENNU WHERE USER_ID=3;");
if(count>0)
System.out.println(" Ok Deletion done");
}
catch(ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
catch(SQLException e)
{
System.out.println(e.getMessage());
}
}
}
当我执行它时,我就是这样的。
答案 0 :(得分:3)
实际上您的DELETE
声明中有错误,但您缺少FROM
个关键字。它应该是
DELETE FROM GENNU WHERE USER_ID=3
看到错误,它指向DELETE
。
更新1
尝试,jdbc:mysql
而非mysql:jdbc
Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/raja"
+ "user=root&password=459805");
答案 1 :(得分:1)
尝试
Class.forName("com.mysql.jdbc.Driver").newInstance();
// The newInstance() call is a work around for some
// broken Java implementations
Class.forName("com.mysql.jdbc.Driver").newInstance();
此外,网址应为
jdbc:mysql://localhost/3306/raja
而不是
mysql:jdbc://localhost/3306/raja
答案 2 :(得分:0)
您需要mySQL Java Connector。您可以在此处的下载页面找到: