MyEclipse中MysqL驱动错误(class not found)
我的代码:publicclassDataTest1{publicstaticvoidmain(String[]args){Stringdriver="com.mysql....
我的代码:
public class DataTest1 {
public static void main(String [] args){
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/Logon";
String username = null;
String password = null;
try{
Scanner sc = new Scanner(System.in);
username = sc.next();
password = sc.next();
Class.forName(driver);
Connection con = DriverManager.getConnection(url, "root", "root");
Statement st = con.createStatement();
st.execute("create table logon(username varchar(20),password varchar(20));");
st.executeUpdate("insert into logon(username,password) values ('"+username+"','"
+password+"');");
ResultSet rs = st.executeQuery("select username,password from logon;");
while(rs.next()){
System.out.println("username:"+rs.next()+"\npassword:"+rs.next());
}
rs.close();
st.close();
con.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
数据库编译器已经连接了:
却出现错误:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.cxpub.chpt12.DataTest1.main(DataTest1.java:21) 展开
public class DataTest1 {
public static void main(String [] args){
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/Logon";
String username = null;
String password = null;
try{
Scanner sc = new Scanner(System.in);
username = sc.next();
password = sc.next();
Class.forName(driver);
Connection con = DriverManager.getConnection(url, "root", "root");
Statement st = con.createStatement();
st.execute("create table logon(username varchar(20),password varchar(20));");
st.executeUpdate("insert into logon(username,password) values ('"+username+"','"
+password+"');");
ResultSet rs = st.executeQuery("select username,password from logon;");
while(rs.next()){
System.out.println("username:"+rs.next()+"\npassword:"+rs.next());
}
rs.close();
st.close();
con.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
数据库编译器已经连接了:
却出现错误:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.cxpub.chpt12.DataTest1.main(DataTest1.java:21) 展开
4个回答
展开全部
能把你的代码发全吗?现在myeclipse导入mysql的Java驱动呀
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
导入mysql的jar包了吗??
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有点纠结!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询