인스턴트 메신저로 작성한 클래스는 무엇일까? 데이터베이스에 연결하는 데 어려움이있다. 도움을 주셔서 감사합니다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에 서버 로컬 호스트에 연결 거부 : 연결합니다.
또는 (아마도) 더비 서버를 시작해야합니다. OP에는 헤드 라인 (mysql)과 본문 (derby) 사이의 상반되는 jdbc url이 포함되었습니다. –