내 생성자의 "사용자 이름"및 "전자 메일"인수가 SQL 테이블에 있는지 확인하려고합니다. 이 같은 ...으로 결과 집합 내 루프를 수행 한 후Java SQL (JDBC) : 다음 열로 이동하는 방법?
String command = "SELECT UserName,Email FROM users WHERE UserName LIKE '" + this.usr.toString() + "';";
resultSet = statement.executeQuery(command);
과 :이 같은 두 개의 열이을 선택 사용하는 경우, 지금
public DB(String usr, String eml, String pwd) {
this.usr = usr;
this.eml = eml;
this.pwd = pwd;
String jdbcUrl = "jdbc:mysql://localhost:3306/registered";
String jdbcUser = "....";
String jdbcPassword = "....";
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(jdbcUrl, jdbcUser,
jdbcPassword);
statement = connection.createStatement();
:
이
내 코드입니다 :while (resultSet.next()) {
if (usr.equalsIgnoreCase(resultSet.getString("UserName"))) {
System.out.println("UserName : " + this.usr + " is taken!");
}
else if (eml.equalsIgnoreCase(resultSet.getString("Email"))) {
System.out.println("Email : " + this.eml + " is taken!");
}
else {
System.out.println("Email : " + this.eml + " and UserName : " + this.usr + " are AVAILABLE!");
command = "INSERT users SET UserName = '" + this.usr.toString() + "',Email = '" + this.eml.toString() + "',Password = '" + this.pwd.toString() + "',Status = '0' ,Connected = '1';";
statement.executeUpdate(command);
}
}
} catch (SQLException e) {
System.out.println("SQLException: " + e.getMessage());
System.out.println("Vendor error: " + e.getErrorCode());
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
resultSet.next는()
단지 "USR은"이, 작동 표에 있지만, "USR"이 존재하지 않는 경우가있는 경우 을 의미한다 "FIRST"열 통해 실행 테이블, 다른 두 문이 작동하지 않습니다 ..
, ... 나는 첫 번째 열과 두 번째를 모두 확인하려고합니다. .. 그리고 아마도 세 번째 또는 더 빨리 ..., 도움이 필요합니까?
무엇이 pstmt.setString (,)입니까? 그래? prepareStatement를 사용하면 제거해야합니다 ** \t \t \t statement = connection.createStatement(); ** ??? – amjazzed
@ user3651124'setString'은 매개 변수 값을 설정합니다 ('? '로 표시). API 문서를 확인하고 JDBC에 익숙해지기 위해 기본 JDBC 자습서를 읽는 것이 좋습니다. –