Commit 2fb99fe8 authored by Deokhyun Lee's avatar Deokhyun Lee

Added private java file and made it untracked

parent 6fb35deb
Pipeline #2102 canceled with stages
...@@ -117,7 +117,8 @@ $RECYCLE.BIN/ ...@@ -117,7 +117,8 @@ $RECYCLE.BIN/
*.msix *.msix
*.msm *.msm
*.msp *.msp
.idea
dao/DBCode.java
# Windows shortcuts # Windows shortcuts
*.lnk *.lnk
......
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
package dao;
public class DBCode {
public static final String USERNAME = "deok";// DBMS접속 시 아이디
public static final String PASSWORD = "deok";// DBMS접속 시 비밀번호
public static final String URL = "jdbc:mysql://222.106.63.122:3306/mytestdb";// DBMS접속할 db명
}
package dao; package dao;
import java.sql.Connection; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
import dto.MemberDto; import dto.MemberDto;
public class MemberDaoImpl implements MemberDao { public class MemberDaoImpl implements MemberDao {
private Connection conn; // DB 커넥션 연결 객체 private Connection conn; // DB 커넥션 연결 객체
private static final String USERNAME = "root";// DBMS접속 시 아이디 private static final String USERNAME = DBCode.USERNAME;// DBMS접속 시 아이디
private static final String PASSWORD = "1234";// DBMS접속 시 비밀번호 private static final String PASSWORD = DBCode.PASSWORD;// DBMS접속 시 비밀번호
private static final String URL = "jdbc:mysql://localhost:3306/aidb";// DBMS접속할 db명 private static final String URL = DBCode.URL;// DBMS접속할 db명
// 생성자에 연결 // 생성자에 연결
public MemberDaoImpl() { public MemberDaoImpl() {
// 디비 연결 부분 // 디비 연결 부분
try {
Class.forName("com.mysql.cj.jdbc.Driver");
conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
System.out.println("드라이버 로딩 성공");
}catch (Exception e){
System.out.println("드라이버 로딩 실패 ");
e.printStackTrace();
try {
conn.close();
} catch (SQLException e1) {
}
}
} }
@Override @Override
public void insert(MemberDto dto) { public void insert(MemberDto dto) {
// TODO Auto-generated method stub String sql = "INSERT INTO mytestdb.major_table (name, major, email) VALUES (?, ?, ?)";
}
@Override PreparedStatement pstmt = null;
public MemberDto selectOne(int n) { try {
// TODO Auto-generated method stub pstmt = conn.prepareStatement(sql);
return null; pstmt.setString(1, dto.getName());
pstmt.setString(2, dto.getMajor());
pstmt.setString(3, dto.getEmail());
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) {
}
}
} }
@Override @Override
public ArrayList<MemberDto> selectAll() { public ArrayList<MemberDto> selectAll() {
// TODO Auto-generated method stub ArrayList<MemberDto> list = new ArrayList<MemberDto>(); // 데이터 담을 그릇
return null; String sql = "SELECT * FROM mytestdb.major_table";
} PreparedStatement pstmt = null;
try {
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
MemberDto dto = new MemberDto();
dto.setName(rs.getString("name"));
dto.setMajor(rs.getString("major"));
dto.setEmail(rs.getString("email"));
list.add(dto);
}
@Override } catch (Exception e) {
public void update(MemberDto dto) { System.out.println("select 메서드 예외발생");
// TODO Auto-generated method stub } finally {
try {
if (pstmt != null && !pstmt.isClosed()) {
pstmt.close();
}
} catch (Exception e2) {
}
}
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);
// }
} }
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