將你的驅(qū)動(dòng)jar包拖到WEN_INF/lib里面試試看怎么操作啊,我不會(huì)弄,能具體點(diǎn)嗎??jī)煞N方法:
1 項(xiàng)目上右擊--》Build Path--》Configure Build Path,默認(rèn)應(yīng)該是在Libraries那個(gè)Tab,然后點(diǎn)Add External Jars,找到你的驅(qū)動(dòng)Jar.
2 直接將你的Jar復(fù)制粘貼到項(xiàng)目WEN_INF/lib目錄下
Java連接MySQL有錯(cuò)誤Sorry,can`t find the Driver!,請(qǐng)各位看一下
Java連接MySQL有錯(cuò)誤Sorry,can`t find the Driver!,請(qǐng)各位看一下
這是提示的錯(cuò)誤
Sorry,can`t find the Driver!
java.lang.ClassNotFoundException: com.mysql.jdbc.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 JDBCTest.main(JDBCTest.java:11)
下面是Java代碼
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class JDBCTest {
public static void main(String[] args){
try {
// 加載驅(qū)動(dòng)程序
Class.forName("com.mysql.jdbc.Driver");
// URL指向要訪問的數(shù)據(jù)庫(kù)名test
String url = "jdbc:mysql://127.0.0.1:3306/test";
// MySQL配置時(shí)的用戶名
String user = "root";
// MySQL配置時(shí)的密碼
String password = "123456";
// 連續(xù)數(shù)據(jù)庫(kù)
Connection connection = DriverManager.getConnection(url, user, password);
if(!connection.isClosed())
System.out.println("Succeeded connecting to the Database!");
// statement用來執(zhí)行SQL語句
Statement statement = connection.createStatement();
// 要執(zhí)行的SQL語句
String sql = "select * from student";
// 執(zhí)行SQL語句并返回結(jié)果集
ResultSet rs = statement.executeQuery(sql);
System.out.println(" 學(xué)號(hào)" + "\t" + " 姓名");
String name = null;
while(rs.next()) {
// 選擇sname這列數(shù)據(jù)
name = rs.getString("sname");
// 輸出結(jié)果
System.out.println(rs.getString("sno") + "\t" + name);
}
// 關(guān)閉結(jié)果集
rs.close();
// 關(guān)閉連接
connection.close();
} catch(ClassNotFoundException e) {
System.out.println("Sorry,can`t find the Driver!");
e.printStackTrace();
} catch(SQLException e) {
e.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
}
}
}
這是提示的錯(cuò)誤
Sorry,can`t find the Driver!
java.lang.ClassNotFoundException: com.mysql.jdbc.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 JDBCTest.main(JDBCTest.java:11)
下面是Java代碼
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class JDBCTest {
public static void main(String[] args){
try {
// 加載驅(qū)動(dòng)程序
Class.forName("com.mysql.jdbc.Driver");
// URL指向要訪問的數(shù)據(jù)庫(kù)名test
String url = "jdbc:mysql://127.0.0.1:3306/test";
// MySQL配置時(shí)的用戶名
String user = "root";
// MySQL配置時(shí)的密碼
String password = "123456";
// 連續(xù)數(shù)據(jù)庫(kù)
Connection connection = DriverManager.getConnection(url, user, password);
if(!connection.isClosed())
System.out.println("Succeeded connecting to the Database!");
// statement用來執(zhí)行SQL語句
Statement statement = connection.createStatement();
// 要執(zhí)行的SQL語句
String sql = "select * from student";
// 執(zhí)行SQL語句并返回結(jié)果集
ResultSet rs = statement.executeQuery(sql);
System.out.println(" 學(xué)號(hào)" + "\t" + " 姓名");
String name = null;
while(rs.next()) {
// 選擇sname這列數(shù)據(jù)
name = rs.getString("sname");
// 輸出結(jié)果
System.out.println(rs.getString("sno") + "\t" + name);
}
// 關(guān)閉結(jié)果集
rs.close();
// 關(guān)閉連接
connection.close();
} catch(ClassNotFoundException e) {
System.out.println("Sorry,can`t find the Driver!");
e.printStackTrace();
} catch(SQLException e) {
e.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
}
}
}
其他人氣:473 ℃時(shí)間:2020-05-27 03:11:39
優(yōu)質(zhì)解答
我來回答
類似推薦
- 美利堅(jiān)合眾國(guó)各州The States of the United States of America
- what do you like to do英語作文,越多越好
- 意思是形容失意時(shí)情緒低落,提不起精神的樣子的四字詞語
- A,B,C為中學(xué)化學(xué)常見化合物,甲,乙,丙為單質(zhì)
- 一件成品為200元的商品標(biāo)出的價(jià)格為400元,現(xiàn)打7.5折出售此商品,則可獲得利潤(rùn) 元,其利潤(rùn)為
- 正方形的邊長(zhǎng)為4厘米,剪去四個(gè)角后成為一個(gè)正八邊形.求這個(gè)正八邊形的邊長(zhǎng)和面積
- 先判斷x與y成什么比例,再填表
- 與Ne的核外電子排布相同的離子跟與Ar的核外電子排布相同的離子所形成的化合物是( ?。?A.MgBr2 B.Na2S C.KCl D.K2S
- 〔 〕花叢 填一動(dòng)詞
- 1個(gè)數(shù)除以3余2,除以5余1,除以7余6,這個(gè)數(shù)是多少?
- 0的英文是什么怎么讀
- 血糖水平神經(jīng)調(diào)節(jié)的反射弧是什么?
猜你喜歡
- 1island怎么讀
- 2whereis she?怎么轉(zhuǎn)換為do you know where she is
- 3求軍訓(xùn)1000字的心得體會(huì)!
- 4帶橋字的成語 越多越好
- 5and only want to sleep with you and have babies with you..maybe i am nota good englsh teacher
- 6請(qǐng)問,正電荷可不可以移動(dòng)?還有,神經(jīng)纖維和神經(jīng)元有關(guān)系嗎?
- 7The studengts have a long holiday in some parts of the US.The school year begins in late August or early Septembeer,and
- 8西電東送工程中,中線和南線的電力主要來自于對(duì)河流中上游的梯級(jí)開發(fā),流域梯級(jí)開發(fā)除發(fā)電外,對(duì)區(qū)域經(jīng)濟(jì)發(fā)展帶來的有利影響有什么(4個(gè))
- 9,甲乙兩筐蘋果共112個(gè),如果從甲筐中拿出蘋果給乙筐,再?gòu)囊铱蛑心贸鑫宸种环湃爰卓?結(jié)果兩筐蘋果就一樣
- 10英語翻譯
- 11that was a statement
- 12生物圈和生態(tài)系統(tǒng)的概念