2013-02-24 76 views
-2

請簡而言之,我如何從eclipse連接到MySQL。如果你可以給我一個簡單的步驟,請舉例。從eclipse連接到mysql

+0

因爲它的問題是無法回答的。你需要詳細說明。你想要一個MySQL客戶端,在這種情況下得到Toad插件。 – Johan 2013-02-24 21:24:03

+0

你想從eclipse IDE(即插件)或從使用Eclipse編寫的'Java'程序連接? – iTech 2013-02-24 21:25:30

+1

谷歌JDBC - 有大量的分步指南。 – 2013-02-24 21:42:25

回答

2
try { 
     Class.forName("com.mysql.jdbc.Driver"); 
     Connection con = DriverManager.getConnection("com.mysql.jdbc:mysql://localhost:3306/NewStudents", "root", "root"); 

     Statement st = con.createStatement(); 
     ResultSet result = st.executeQuery("select * from students"); 

     while (result.next()) { 
      ..... 
     } 
    } 
    catch (ClassNotFoundException e) { 
     System.out.println("Driver not found"); 
    } 
    catch (SQLException e) { 
     e.printStackTrace(); 

getConnection的第一個參數是url,第二個用戶名,第三個密碼。 還通過將它添加到您的項目的庫中來導入de jdbc驅動程序。

有更好的方法,但這對初學者很簡單。

這是一個相同的鏈接,它解釋更多。

http://www.stardeveloper.com/articles/display.html?article=2003090401&page=1