Vous devez utiliser JDBC. Voir http://en.wikipedia.org/wiki/Java_Database_Connectivity
Vous avez besoin de Java MySQL Connector de http://dev.mysql.com/downloads/connector/j/
Ensuite, utilisez quelque chose comme (copié à partir de l'article de Wikipedia):
Class.forName("com.mysql.jdbc.driver");
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost/database",
"myLogin",
"myPassword");
try {
Statement stmt = conn.createStatement();
try {
ResultSet rs = stmt.executeQuery("SELECT * FROM Table WHERE color = 'blue'");
try {
while (rs.next()) {
int numColumns = rs.getMetaData().getColumnCount();
for (int i = 1 ; i <= numColumns ; i++) {
// Column numbers start at 1.
// Also there are many methods on the result set to return
// the column as a particular type. Refer to the Sun documentation
// for the list of valid conversions.
System.out.println("COLUMN " + i + " = " + rs.getObject(i));
}
}
} finally {
try { rs.close(); } catch (Throwable ignore) { /* Propagate the original exception
instead of this one that you may want just logged */ }
}
} finally {
try { stmt.close(); } catch (Throwable ignore) { /* Propagate the original exception
instead of this one that you may want just logged */ }
}
} finally {
//It's important to close the connection when you are done with it
try { conn.close(); } catch (Throwable ignore) { /* Propagate the original exception
instead of this one that you may want just logged */ }
}
Dans d'autres question similaire trouvé [cet article jdbc-select-fiches] (https://www.tutorialspoint.com/jdbc/jdbc-select-records.htm) USEFULL. – surfmuggle