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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.io.IOException;
public class jdbc {
public static void main(String[] args) {
String url = "jdbc:mysql://localhost";
String user = "admin";
String password = "admin1";
try{
Class.forName("com.mysql.jdbc.Driver");
}catch (ClassNotFoundException jdbc){
System.out.println(jdbc.toString());}
try {
Connection con = DriverManager.getConnection( url, user, password);
Statement stmt = con.createStatement();
String q1 = "SELECT * from table1";
ResultSet rs1 = stmt.executeQuery(q2);
String n;
while(rs1.next()){
for (int i=0 ; i<=3; i++)
n = rs1.getString(i);
System.out.println(n);
}
con.close();
} catch (SQLException ex) {
System.out.println("Echec connection!!" );
}
}
} |