Du skal faktisk gøre følgende:
1) Installer MySQL (formentlig allerede udført)
2) Download en MySQL JDBC-driver, og sørg for, at den er i dit Eclipse-projekts CLASSPATH.
3) Skriv dit program for at bruge JDBC. For eksempel (utestet):
private Connection connect = null;
private Statement statement = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connect =
DriverManager.getConnection("jdbc:mysql://localhost/xyz?"
+ "user=sqluser&password=sqluserpw");
String query = "INSERT INTO records (id, time) VALUES (?, ?)";
PreparedStatement preparedStmt = conn.prepareStatement(query);
preparedStmt.setInt (1, null);
preparedStmt.setDate (2, new java.util.Date());
preparedStmt.executeUpdate();
} catch (SQLException e) {
...
}
Her er et par gode tutorials:
http://www.vogella.com/tutorials/MySQLJava/article.html
http://www.mkyong.com/jdbc/ jdbc-preparestatement-example-insert-a-record/