报错Class not found com.imooc.jdbc.demo1.JDBCDemo2
package com.imooc.jdbc.demo1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import org.junit.Test;
public class JDBCDemo2 {
@Test
/*
* 保存操作
*/
public void demo1() {
Connection conn = null;
Statement stmt = null;
try {
// 注册驱动
Class.forName("com.mysql.cj.jdbc.Driver");
// 获得连接
conn = DriverManager.getConnection(
"jdbc:mysql:///jdbctest"
+ "?useSSL=false&serverTimezone=Hongkong&useUnicode=true&characterEncoding=utf-8",
"root", "1234");
// 获得执行SQL语句的对象:
stmt = conn.createStatement();
// 编写SQL
String sql = "insert user values(null,'eee','123','张三')";
// 执行SQL
int i = stmt.executeUpdate(sql);
// 大于0说明影响成功
if (i > 0) {
System.out.println("保存成功!");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
// 释放资源
if (stmt != null) {
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
stmt = null;
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
conn = null;
}
}
}
}
正在回答 回答被采纳积分+1
Class not found com.imooc.jdbc.demo1.JDBCDemo2
java.lang.ClassNotFoundException: com.imooc.jdbc.demo1.JDBCDemo2
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClass(RemoteTestRunner.java:773)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.loadClasses(RemoteTestRunner.java:502)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:525)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
- 参与学习 人
- 提交作业 357 份
- 解答问题 8016 个
本阶段将带你学习MySQL数据库,JDBC接口,MyBatis框架等,带你掌握的数据的存放和管理。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星