import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import com.tmax.tibero.jdbc.ext.TbConnectionPoolDataSource;
import com.tmax.tibero.jdbc.*;
public class UserDAO {
// dao : 데이터베이스 접근 객체의 약자로서
// 실질적으로 db에서 회원정보 불러오거나 db에 회원정보 넣을때
Statement st=null;
ResultSet rs=null;
Connection con= null; // connection:db에접근하게 해주는 객체
Statement pstmt =null;
// public static void main(String[] args) {
// // create tiberoConnection instance
//
// UserDAO a=new UserDAO();
// a.join(new User("321","322","553","xcv4","xcv5"));
//
//
// }
//
//
//
InitialContext initCtx;
DataSource ds ;
public UserDAO()throws SQLException {
try {
initCtx = new InitialContext();
ds = (DataSource) initCtx.lookup("Databasesource1");
}
catch (NamingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
public int login(String userID, String userPassword) {
String SQL= "SELECT userPassword FROM USERS WHERE userID = '"+userID+"'";
try {
//export-name과 일치 시킵니다.
con=ds.getConnection();
st=con.createStatement();
rs=st.executeQuery(SQL);
if (rs.next()) {
// 패스워드 일치한다면 실행
System.out.println(rs.getObject(1));
if (rs.getString(1).equals(userPassword)) {
return 1; // 라긴 성공
} else
return 0; // 비밀번호 불일치
}
return -1; // 아이디가 없음 오류
} catch (Exception e) {
e.printStackTrace();
}
return -2;
}
public int join(User user) {
String SQL = "INSERT INTO USERS VALUES ('"+user.getUserID()+"','"+user.getUserPassword()+"','"+user.getUserName()+"','"+user.getUserGender()+"','"+user.getUserEmail()+"')";
try {
System.out.print(SQL);
con=ds.getConnection();
st=con.createStatement();
rs=st.executeQuery(SQL);
} catch (Exception e) {
e.printStackTrace();
}
return -1; // DB 오류
}
public void disconnect() {
if (con != null) {
try { con.close();
}
catch (SQLException e) {
System.err.println("Disconnect Error");
}
}
}
}
소스코드에 잡다한 문을 많이 넣었다. 예제라고 생각하고 삭제할것은 삭제하는 과감한 선택 부탁드립니다.
기본적으로 디베로에 [tibero-home]/client/lib/jar/tibero-jdbc-숫자.jar파일을 톰켓이나 java_home/jre/lib/ext/에 넣어줘야한다.
이클립스를 쓴다면 jar파일 추가하는 방법을 찾아 적용하세요
'프로그래밍' 카테고리의 다른 글
[이클립스]프로젝트 jdk 버전 변경하기 (0) | 2020.01.21 |
---|---|
[티베로]jsp, java JDBC로 연결하기 (0) | 2020.01.21 |
[JEUS]javax.naming.NameNotFoundException: 해결 (0) | 2020.01.21 |
비쥬얼코드 java 연동 (0) | 2020.01.21 |
String conversion 인코딩 해주는 온라인 사이트 (0) | 2019.02.01 |