eclipse 运行代码出现错误 Exception in thread "main" java.lang.ClassNotFo。。。 30
Exceptioninthread"main"java.lang.ClassNotFoundException:com.mysql.jbdc.Driveratjava.n...
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jbdc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at gjxweb.sql1.main(sql1.java:6)
(驱动已经添加了)代码如下:
import java.sql.*;
public class sql1 {
public static void main(String[] args) throws Exception{
Class.forName("com.mysql.jbdc.Driver");
Connection conn=DriverManager.getConnection("jbdc:mysql://localhost:3306?mytest","root","123456");
PreparedStatement pstmt =conn.prepareStatement("SELECT * from user where username=?");
pstmt.setString (1,"test1");
ResultSet rs=pstmt.executeQuery();
if(rs.first()){
System.out.println("查到的"+rs.getString("username")+"用户的密码为"+rs.getString("password"));
}
rs.close();pstmt.close();conn.close();
}
} 展开
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at gjxweb.sql1.main(sql1.java:6)
(驱动已经添加了)代码如下:
import java.sql.*;
public class sql1 {
public static void main(String[] args) throws Exception{
Class.forName("com.mysql.jbdc.Driver");
Connection conn=DriverManager.getConnection("jbdc:mysql://localhost:3306?mytest","root","123456");
PreparedStatement pstmt =conn.prepareStatement("SELECT * from user where username=?");
pstmt.setString (1,"test1");
ResultSet rs=pstmt.executeQuery();
if(rs.first()){
System.out.println("查到的"+rs.getString("username")+"用户的密码为"+rs.getString("password"));
}
rs.close();pstmt.close();conn.close();
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询