该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
显示
错误: 找不到或无法加载主类 JDBCTest02
原因: java.lang.ClassNotFoundException: JDBCTest02
classpath也配置了呀:
D:\应用安装\mysql-connector-java-8.0.22\mysql-connector-java-8.0.22.jar
代码如下:
import java.sql.*;
public class JDBCTest02{
public static void main(String args){
Connection conn = null;
Statement stmt = null;
try{
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
String ulr = "jdbc:mysql://127.0.0.1:3306/vannode";
String user = "root";
String password = "333";
conn = DriverManager.getConnection(ulr,user,password);
stmt = conn.createStatement();
String sql = "delete from dept where deptno = 40";
int count = stmt.executeUpdate(sql);
System.out.println(count == 1 ? "删除成功" : "删除失败");
}catch(SQLException e){
e.printStackTrace();
}finally{
if(stmt != null){
try{
stmt.close();
}catch(SQLException e){
e.printStackTrace();
}
}
if(conn !=null ){
try{
conn.close();
}catch(SQLException e){
e.printStackTrace();
}
}
}