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 55 56 57 58 59 60 61
|
import java.sql.*;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Abdellqtif
*/
public class jdbc
{
public static void main(String[] s)
{
String utilisateur="root";
String mdp="";
String lien="jdbc:mysql://127.0.0.1:3306/gab";
String requete="SELECT login,passwd,Ncompte,solde FROM client";
try{
Class.forName("com.mysql.jbdc.Driver");
}catch(java.lang.ClassNotFoundException e)
{
System.err.print("ClassNotFoundException :");
System.err.println(e.getMessage());
}
try{
Connection con;
Statement stmt;
con=DriverManager.getConnection(lien,utilisateur,mdp);
System.out.println("OK,connetion avec succe !!");
stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(requete);
while(rs.next())
{
String l=rs.getString("login");
int n=rs.getInt("Ncompte");
int x=rs.getInt("passwd");
System.out.println("le compte "+n+":login="+l+" passwd="+x);
}
stmt.close();
con.close();
}
catch(SQLException ex)
{
System.err.println("==>SQLException : ");
while(ex!=null)
{
System.out.println("message"+ex.getMessage());
System.out.println("message"+ex.getSQLState());
System.out.println("message"+ex.getErrorCode());
ex=ex.getNextException();
System.out.println("");
}
}
}
} |
Partager