packageJDBChomework;importjava.sql.*;publicclassJDBCclient{
{publicstaticvoidmain(String[]args){Connectioncon=null;try{//1.加载驱动StringdriverClassName=”com.mysql.jdbc.Dr…
package JDBChomework;
import java.sql.*;
public class JDBCclient {
{
public static void main(String[] args){
Connection con = null;
try{
//1.加载驱动
String driverClassName =
“com.mysql.jdbc.Driver”;
Class.forName(driverClassName).newInstance();
//2.连接数据库
String url =
“jdbc:mysql://localhost:3306/sample_db?user=root&password=your_password”;
String Url=”jdbc:mysql://localhost:3306/sample_db?user=root&password=your_password”;
con=DriverManager.getConnection(Url, “user”,”Password”);
System.out.println(“con->”+
con.getClass());
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(con!=null) con.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
}
}
错误显示
java.lang.NoClassDefFoundError: JDBChomework/JDBCclient
Exception in thread “main”
展开