java连接mysql出错,不知道哪里出问题了。在线等。
publicvoidconn(){Stringurl="jdbc:mysql://localhost:3306/myweb";//URL指向要访问的数据库名mytestS...
public void conn() {
String url="jdbc:mysql://localhost:3306/myweb";
// URL指向要访问的数据库名mytest
String driver = "com.mysql.jdbc.Driver";
try {
Class.forName(driver);
}catch (Exception e) {
System.out.println("加载出错");
e.printStackTrace();
}try{
con=DriverManager.getConnection(url, "root", "111111");
st=con.createStatement();
rSet=st.executeQuery("select * from test");
con.close();
st.close();
if (rSet!=null) {
rSet.close();
}
System.out.println("yes");
} catch (Exception e) {
// TODO: handle exception
System.out.println("no");
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 Test.DBhelp.conn(DBhelp.java:23)
at Test.DBhelp.main(DBhelp.java:13)
no
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/myweb
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at Test.DBhelp.conn(DBhelp.java:28)
at Test.DBhelp.main(DBhelp.java:13) 展开
String url="jdbc:mysql://localhost:3306/myweb";
// URL指向要访问的数据库名mytest
String driver = "com.mysql.jdbc.Driver";
try {
Class.forName(driver);
}catch (Exception e) {
System.out.println("加载出错");
e.printStackTrace();
}try{
con=DriverManager.getConnection(url, "root", "111111");
st=con.createStatement();
rSet=st.executeQuery("select * from test");
con.close();
st.close();
if (rSet!=null) {
rSet.close();
}
System.out.println("yes");
} catch (Exception e) {
// TODO: handle exception
System.out.println("no");
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 Test.DBhelp.conn(DBhelp.java:23)
at Test.DBhelp.main(DBhelp.java:13)
no
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/myweb
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at Test.DBhelp.conn(DBhelp.java:28)
at Test.DBhelp.main(DBhelp.java:13) 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询