Commit fdb013f6 authored by Deokhyun Lee's avatar Deokhyun Lee

added logIn and singUpForm methods

parent 553b95fc
...@@ -9,3 +9,4 @@ ...@@ -9,3 +9,4 @@
/db_java.iml /db_java.iml
/.idea/ /.idea/
/src/dao/DBCode.java /src/dao/DBCode.java
out/
\ No newline at end of file
...@@ -27,6 +27,7 @@ public class MemberDaoImpl implements MemberDao { ...@@ -27,6 +27,7 @@ public class MemberDaoImpl implements MemberDao {
} }
} }
@Override @Override
public void insert(MemberDto dto) { public void insert(MemberDto dto) {
String sql = "INSERT INTO mytestdb.major_table (name, major, email) VALUES (?, ?, ?)"; String sql = "INSERT INTO mytestdb.major_table (name, major, email) VALUES (?, ?, ?)";
...@@ -100,4 +101,64 @@ public class MemberDaoImpl implements MemberDao { ...@@ -100,4 +101,64 @@ public class MemberDaoImpl implements MemberDao {
e.printStackTrace(); e.printStackTrace();
} }
} }
public void insertSignUpForm(String name, String major, String email, String password) {
String sql = "INSERT INTO mytestdb.major_table (name, major, email, password) VALUES (?, ?, ?,?)";
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
if (rs.getString("email").equals(name)) {
System.out.println("Email already exists in the database.");
break;
}
}
pstmt.setString(1, name);
pstmt.setString(2, major);
pstmt.setString(3, email);
pstmt.setString(4, password);
int result = pstmt.executeUpdate();
if (result == 1) {
System.out.println("회원가입 성공!");
}
} catch (Exception e) {
System.out.println("회원가입 실패!");
} finally {
try {
if (pstmt != null && !pstmt.isClosed()) {
pstmt.close();
}
} catch (Exception e2) {
}
}
}
public void logIn (String email, String password){
String sql = "SELECT * FROM mytestdb.major_table";
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
if (rs.getString("email").equals(email) && rs.getString("password").equals(password)){
System.out.println("로그인 성공!");
}
}
} catch (Exception e) {
System.out.println("logIn 메서드 예외발생");
} finally {
try {
if (pstmt != null && !pstmt.isClosed()) {
pstmt.close();
}
} catch (Exception e2) {
}
}
}
} }
\ No newline at end of file
package member; package member;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Scanner;
import dao.MemberDaoImpl; import dao.MemberDaoImpl;
import dto.MemberDto; import dto.MemberDto;
...@@ -22,7 +23,16 @@ public class MainClass { ...@@ -22,7 +23,16 @@ public class MainClass {
// 데이터 보기 // 데이터 보기
System.out.println(memberDao.selectAll()); System.out.println(memberDao.selectAll());
// 데이터 수정 // 데이터 수정
System.out.println("1 로 회원가입; 2 로 로그인");
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
sc.nextLine();
if (num == 1){
}else if (num == 2){
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment