我對編程非常陌生,所以請耐心等待,並提前道歉,如果一開始我沒有道理......!如何在Eclipse中使用MySql數據庫
我正在做一個本科的編程項目,並且需要在Java程序中創建一些數據庫。我正在使用eclipse(galilo)編寫我的程序。我已經下載了一個連接器/ J,但沒有模糊我應該如何使用它!
任何人都可以給我一步一步的方法?
非常感謝!
我對編程非常陌生,所以請耐心等待,並提前道歉,如果一開始我沒有道理......!如何在Eclipse中使用MySql數據庫
我正在做一個本科的編程項目,並且需要在Java程序中創建一些數據庫。我正在使用eclipse(galilo)編寫我的程序。我已經下載了一個連接器/ J,但沒有模糊我應該如何使用它!
任何人都可以給我一步一步的方法?
非常感謝!
如果您需要在Eclipse裏面某種類型的數據資源管理器,你可以看一下插件的文檔上面或者更具體地說提供的鏈接。
OTOH,如果你想知道如何使用JDBC連接到mysql數據庫,下面的代碼示例解釋了它。
Connection connection = null;
try {
//Loading the JDBC driver for MySql
Class.forName("com.mysql.jdbc.Driver");
//Getting a connection to the database. Change the URL parameters
connection = DriverManager.getConnection("jdbc:mysql://Server/Schema", "username", "password");
//Creating a statement object
Statement stmt = connection.createStatement();
//Executing the query and getting the result set
ResultSet rs = stmt.executeQuery("select * from item");
//Iterating the resultset and printing the 3rd column
while (rs.next()) {
System.out.println(rs.getString(3));
}
//close the resultset, statement and connection.
rs.close();
stmt.close();
connection.close();
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
謝謝你們,非常感謝 – 2010-03-21 18:27:01