2014-11-14 3 views
0

인스턴트 메신저로 작성한 클래스는 무엇일까? 데이터베이스에 연결하는 데 어려움이있다. 도움을 주셔서 감사합니다jdbc : mysql : // localhost : 3306

나는 더비를 시도했지만 제 데이터베이스는 xampp을 사용하여 mysql에 있습니다.

Statement stmnt; 
    ResultSet rs; 
    try{ 
     String host = "jdbc:derby://localhost:3306/population"; 
     String uName= "root"; 
     String uPass="root"; 
     Connection con = DriverManager.getConnection(host, uName, uPass); 
     //execute some sql and load into the result set 
     stmnt = con.createStatement(); 
     String sql = "SELECT * FROM users_admin"; 
     rs = stmnt.executeQuery(sql); 
     //move the cursor the first record and get the data 
     rs.next(); 
     int id = rs.getInt("admin_id"); 
     String id_admin = Integer.toString(id); 
     String username=rs.getString("username"); 
     String pwd = rs.getString("password"); 

     ta_user.setText(username); 
     ta_pwd.setText(pwd); 
     ta_id.setText(id_admin); 


    } 
    catch(SQLException err){ 
     System.out.println(err.getMessage()); 
    } 

내 다른 샘플 프로젝트의 코드가 오류를 보여줍니다 것을 시도했다 :

java.net.ConnectException : 오류 메시지 연결에 포트 3306에 서버 로컬 호스트에 연결 거부 : 연결합니다.

답변

2

좋은 소식! Class.forName이 필요없고 JDBC 드라이버가 성공적으로로드되었습니다. 이제 mysql 서버 또는 derby 서버에 두 개의 서로 다른 jdbc url (s)을 사용하여 포트 3306에서 연결 대기 중이다.

0

필요하지 않습니다. Connection refused은 드라이버가 완벽하게 작동하고 있으며 MySQL 또는 Derby 데이터베이스 서버 (제목 및 질문에 모순되는 URL 중 어떤 것이 믿어 지는지)가 localhost에 시작되지 않았거나 설치 될 가능성이 있음을 나타냅니다.

+0

또는 (아마도) 더비 서버를 시작해야합니다. OP에는 헤드 라인 (mysql)과 본문 (derby) 사이의 상반되는 jdbc url이 포함되었습니다. –

관련 문제