sql 연동하는 코드인데


Connection con = null;

Statement stmt = null;

try{

Class.forName("com.mysql.jdbc.Driver");

con = (Connection)DriverManager.getConnection("jdbc:mysql://localhost:3306/managementsystem", "root","1234" );

stmt = con.createStatement();

ResultSet rs = stmt.executeQuery("select id, password from idpw;");

if(con != null)

{

System.out.println("연결 성공");

}

while(rs.next())

{

count++;

id[i] = rs.getString("id");

pw[i] = rs.getString("password");

System.out.printf("%s, %s\n", id[i], pw[i]);

}

}catch(Exception e)

{

System.out.println("연결 실패");

}



이렇게 해놨걷느 근데 이상한게 저기 if문에 con != null 이라고 해놨잖아 근데 저게 

con != null 이든 , con == null 이든 무조건 catch 문으로 빠져서 연결실패가 콘솔창에 뜨거든 

con 이 널인경우 널이 아닌경우 둘중에 하나는 걸려서 연결 성공이 떠야하는거 아닌가해서.....

왜 이런건지 도저히 이해가 안되는데 형들 좀 도와줘