一个简单的JDBC到MySQL数据库连接的示例,确保数据库中包含test数据库,并且其中有表ttt,表中有ID列,并包含ID为123的数据.
import java.sql.*;


public class SampleConnection ...{

public static void main(String[] args) ...{

try ...{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","username","password");
Statement stat = conn.createStatement();
stat.executeUpdate("delete from ttt where ID = '123'");
conn.close();
}

catch(Exception e) ...{
e.printStackTrace();
}
}
}
import java.sql.*;

public class SampleConnection ...{
public static void main(String[] args) ...{
try ...{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","username","password");
Statement stat = conn.createStatement();
stat.executeUpdate("delete from ttt where ID = '123'");
conn.close();
}
catch(Exception e) ...{
e.printStackTrace();
}
}
}
本文提供了一个使用Java JDBC连接到MySQL数据库并执行删除操作的简单示例。示例中假设存在名为test的数据库及其内的ttt表,且该表中包含ID为123的数据。
385

被折叠的 条评论
为什么被折叠?



