1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| import java.sql.*;
public class exjdbc{
public static void main (String[] args){
String query="select* from hayet.users";
String url="jdbc:mysql://localhost/hayet";
String username="root";
String password="";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection maconnexion=DriverManager.getConnection(url,username,password);
System.out.println("connexion établie with succes");
Statement st=maconnexion.createStatement();
ResultSet rs= st.executeQuery(query);
while (rs.next()){
System.out.println("login="+rs.getString("login"));
System.out.println("mdp="+rs.getString("mdp"));}
}
catch(Exception e){System.out.println(e.getMessage());}
}
} |