Why, when I program in java, the connection to a mysql database, managed by phpmyadmin, using the Singleton Pattern design pattern, is it impossible for me to access the records of the tables in that database, because i see the message in console : "Access was denied to user 'x'" , but when I do not use the Singleton Pattern design pattern, it is possible to access the records in the tables in the 'x' database?
public static void main(String[] args) {
// TODO code application logic here
String usr = "************";
String pwd = "**********";
String driver = "**********";
String url = "*************";
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try{
//parte >>> 1
Class.forName(driver);
con = DriverManager.getConnection(url, usr, pwd);
//con = Uconnection.getConnection();
//parte >>> 2
String sql = "SELECT ***,***,***,*** FROM ***";
pstm = con.prepareStatement(sql);
rs = pstm.executeQuery();
while(rs.next()){
System.out.print(rs.getInt("***")+" ");
System.out.print(rs.getString("***")+" ");
System.out.print(rs.getDate("***")+" ");
//System.out.print(rs.getString("***")+" ");
System.out.println(rs.getInt("***"));
}
}catch(Exception ex){
ex.printStackTrace();
throw new RuntimeException(ex);
}finally{
//parte >>> 3
try{
if(rs != null)rs.close();
if(pstm != null)pstm.close();
if(con != null)con.close();
}catch(Exception ex){
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
}
before Implements singleton pattern
public static void main(String[] args) {
Connection con = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try{
//parte >>> 1
con = Uconnection.getConnection();
//parte >>> 2
String sql = "SELECT ***,***,***,*** FROM ***";
pstm = con.prepareStatement(sql);
rs = pstm.executeQuery();
while(rs.next()){
System.out.print(rs.getInt("***")+" ");
System.out.print(rs.getString("***")+" ");
System.out.print(rs.getDate("***")+" ");
//System.out.print(rs.getString("***")+" ");
System.out.println(rs.getInt("***"));
}
}catch(Exception ex){
ex.printStackTrace();
throw new RuntimeException(ex);
}finally{
//parte >>> 3
try{
if(rs != null)rs.close();
if(pstm != null)pstm.close();
if(con != null)con.close();
}catch(Exception ex){
ex.printStackTrace();
throw new RuntimeException(ex);
}
}
}
after implements singleton pattern
Aucun commentaire:
Enregistrer un commentaire