1

这是我的代码片段,

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());
        }
    }
}

当我执行它时,我得到了这样的结果。 在此处输入图像描述

4

3 回答 3

3

实际上,您的陈述中有错误DELETE,您缺少FROM关键字。它应该是

DELETE FROM GENNU WHERE USER_ID=3

看到错误,它指向DELETE.

更新 1

试试,jdbc:mysqlmysql:jdbc

Class.forName("com.mysql.jdbc.Driver");
connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/raja"
              + "user=root&password=459805");
于 2012-12-16T13:26:36.503 回答
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();

此外,URL 应该是

jdbc:mysql://localhost/3306/raja

并不是

mysql:jdbc://localhost/3306/raja
于 2012-12-16T13:30:07.590 回答
0

您需要 mySQL Java 连接器。您可以在此处的下载页面找到:

https://www.mysql.com/products/connector/

于 2012-12-16T13:26:27.450 回答