1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
import java.sql.*;
public class db {
public static void main (String [] args) throws ClassNotFoundException, SQLException{
Connection con = null ;
Statement sta = null ;
ResultSet result = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String url = "jdbc:mysql://localhost/mydb";
con = (Connection) DriverManager.getConnection(url,"user","motdepasse");
sta = (Statement) con.createStatement();
String requete = "SELECT name FROM essai";
result = sta.executeQuery(requete);
while (result.next()) {
System.out.println(result);
}
} catch(SQLException s){
s.getMessage();
}
}
} |
Partager