創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!
這篇文章主要介紹mysql與eclipse建立連接的方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
mysql與eclipse建立連接的步驟:
1、打開Eclipse,創(chuàng)建一個項目(my),
操作:右鍵點擊my--->build Path--->add external Archiver...選擇jdbc驅(qū)動,點擊確定。
我的項目列表:
2、驅(qū)動已經(jīng)導(dǎo)入,下面我們來寫一個程序驗證一下
import java.sql.*; publicclass MysqlJdbc { publicstaticvoid main(String args[]) { try { Class.forName("com.mysql.jdbc.Driver"); //加載MYSQL JDBC驅(qū)動程序 //Class.forName("org.gjt.mm.mysql.Driver"); System.out.println("Success loading Mysql Driver!"); } catch (Exception e) { System.out.print("Error loading Mysql Driver!"); e.printStackTrace(); } try { Connection connect = DriverManager.getConnection( "jdbc:mysql://localhost:3306/test","root","198876"); //連接URL為 jdbc:mysql//服務(wù)器地址/數(shù)據(jù)庫名 ,后面的2個參數(shù)分別是登陸用戶名和密碼 System.out.println("Success connect Mysql server!"); Statement stmt = connect.createStatement(); ResultSet rs = stmt.executeQuery("select * from user"); //user 為你表的名稱 while (rs.next()) { System.out.println(rs.getString("name")); } } catch (Exception e) { System.out.print("get data error!"); e.printStackTrace(); } } }
點擊運行程序:
Success loading Mysql Driver!
Success connect Mysql server!
huzhiheng
出現(xiàn)上面結(jié)果,說明連接數(shù)據(jù)庫成功。
以上是mysql與eclipse建立連接的方法的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道!
本文題目:mysql與eclipse建立連接的方法-創(chuàng)新互聯(lián)
鏈接地址:http://www.rwnh.cn/article36/dciisg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)、App設(shè)計、全網(wǎng)營銷推廣、外貿(mào)建站、標簽優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容