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
| public String[] lireLaBase(){
String[] rep ;
rep = new String[]{"0"};
int i=0;
String url ="jdbc:mysql://localhost/dbrecette";
String login ="root";
String mdp="";
Connection cn=null;
Statement st= null;
ResultSet rs=null;
try {
Class.forName("com.mysql.jdbc.Driver");
cn = DriverManager.getConnection(url, login, mdp);
st=cn.createStatement();
String sql="Select labelmetier FROM metier";
rs=st.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getString("libelmetier"));
rep[i]=rs.getString("libelmetier");
i++;
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch(SQLException e){
e.printStackTrace();
}finally{
try {
cn.close();
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return rep;
} |
Partager