more..
package hufs.Database;
/**
* 데이터베이스 접속 클래스
*
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;
public class DatabaseConn { // DB 커넥션초기화
private String DB_URL = "Jdbc:Odbc:info";
private String DB_USER = "root";
private String DB_PASSWORD = "12345";
Connection conn = null;
public Connection getConnection() { // DB 커넥션 얻음
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
try {
Properties props = new Properties();
props.put("charSet", "8859_1");
props.put("user", DB_USER);
props.put("password", DB_PASSWORD);
conn = DriverManager.getConnection(DB_URL, props);
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public void disConnection(ResultSet rs, PreparedStatement psmt,
Connection conn) { // DB 접속 해제
try {
rs.close();
psmt.close();
conn.close();
} catch (Exception e) {
}
}
}
Login.java
more..
package hufs.Database;
/*
* 로그인 인증 클래스
*/
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class Login {
public Login() {
}
public int login(String user, String passwd) {
DatabaseConn dbConn = new DatabaseConn(); // DB 접속
Connection conn = null;
PreparedStatement psmt = null;
ResultSet rs = null;
String USER = null;
String PASSWD = null;
try {
String sql = " SELECT USER, PASSWD FROM login where USER='" + user
+ "' and PASSWD ='" + passwd + "'"; // 쿼리문
conn = dbConn.getConnection();
psmt = conn.prepareStatement(sql);
rs = psmt.executeQuery(); // 쿼리 실행
while (rs.next()) {
USER = new String(rs.getString("USER").getBytes("8859_1"),
"euc-kr");
PASSWD = new String(rs.getString("PASSWD").getBytes("8859_1"),
"euc-kr");
System.out.println(USER + PASSWD);
}
if (USER == null || PASSWD == null) // 아이디 또는 비밀번호가 일치하지 않을때
return -1;
} catch (Exception e) {
System.out.println("SQL ERROR");
} finally {
dbConn.disConnection(rs, psmt, conn); // DB 접속 해제
}
return 0;
}
}
댓글 없음:
댓글 쓰기