Commit 7875287e authored by Deokhyun Lee's avatar Deokhyun Lee

Added update() and fixed some errors

parent 33b09b76
Pipeline #2107 canceled with stages
......@@ -10,11 +10,12 @@ public interface MemberDao {
// 데이터 보기
// 데이터 한개 보기
public MemberDto selectOne(int n);
//public MemberDto selectOne(int n);
// 데이터 전체 보기
public ArrayList<MemberDto> selectAll();
// 데이터 수정
public void update(MemberDto dto);
public void update(String name, String changedName);
}
......@@ -17,7 +17,7 @@ public class MemberDaoImpl implements MemberDao {
Class.forName("com.mysql.cj.jdbc.Driver");
conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
System.out.println("드라이버 로딩 성공");
}catch (Exception e){
} catch (Exception e) {
System.out.println("드라이버 로딩 실패 ");
e.printStackTrace();
try {
......@@ -86,17 +86,18 @@ public class MemberDaoImpl implements MemberDao {
return list;
}
// @Override
// public void update(MemberDto dto) {
// String sql = "UPDATE mytestdb.major_table SET title=? WHERE num=?";
// PreparedStatement pstmt = null;
// try {
// pstmt = conn.prepareStatement(sql);
// pstmt.setString(1, "제목 수정");
// pstmt.setInt(2, id);
// pstmt.executeUpdate();
// System.out.println("수정된 id: " + id);
// }
@Override
public void update(String name, String changedName) {
String sql = "UPDATE mytestdb.major_table SET name=? WHERE name=?";
PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, changedName);
pstmt.setString(2, name);
pstmt.executeUpdate();
System.out.println("수정된 이름: " + changedName);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
\ No newline at end of file
......@@ -2,27 +2,28 @@ package member;
import java.util.ArrayList;
import dao.MemberDaoImpl;
import dto.MemberDto;
public class MainClass {
public static void main(String[] args) {
// 멤버 정보 DB 활용
MemberDaoImpl memberDao = new MemberDaoImpl();
// 파일에 있는 데이터를 읽어오기
String filePath = "C:/dev/file/전공정보.txt";
String filePath = "/Users/ideoghyeon/Desktop/전공.txt";
Member member = new Member();
// System.out.println("쉼표로 구분되는 데이터 갯수: " + spData.length);
// 읽어온 데이터를 DB에 넣기
ArrayList<MemberDto> list = member.getMemberList(filePath);
for (MemberDto d : list) {
System.out.println(d.getName());
memberDao.insert(d);
}
// System.out.println("쉼표로 구분되는 데이터 갯수: " + spData.length);
// 읽어온 데이터를 DB에 넣기
// 데이터 보기
System.out.println(memberDao.selectAll());
// 데이터 수정
}
}
......@@ -14,10 +14,9 @@ public class Member {
for (String s : spList) {
MemberDto dto = new MemberDto();
String[] sp = s.split(",");
dto.setNum(Integer.parseInt(sp[0])); // 문자열을 숫자로
dto.setName(sp[1]);
dto.setMajor(sp[2]);
dto.setEmail(sp[3]);
dto.setName(sp[0]);
dto.setMajor(sp[1]);
dto.setEmail(sp[2]);
retList.add(dto);
}
return retList;
......
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