Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
db_studies
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Deokhyun Lee
db_studies
Commits
7875287e
Commit
7875287e
authored
Dec 02, 2021
by
Deokhyun Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added update() and fixed some errors
parent
33b09b76
Pipeline
#2107
canceled with stages
Changes
11
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
32 additions
and
30 deletions
+32
-30
Util.class
out/production/db_java/com/ldk/util/Util.class
+0
-0
DBCode.class
out/production/db_java/dao/DBCode.class
+0
-0
MemberDao.class
out/production/db_java/dao/MemberDao.class
+0
-0
MemberDaoImpl.class
out/production/db_java/dao/MemberDaoImpl.class
+0
-0
MemberDto.class
out/production/db_java/dto/MemberDto.class
+0
-0
MainClass.class
out/production/db_java/member/MainClass.class
+0
-0
Member.class
out/production/db_java/member/Member.class
+0
-0
MemberDao.java
src/dao/MemberDao.java
+3
-2
MemberDaoImpl.java
src/dao/MemberDaoImpl.java
+18
-17
MainClass.java
src/member/MainClass.java
+8
-7
Member.java
src/member/Member.java
+3
-4
No files found.
out/production/db_java/com/ldk/util/Util.class
0 → 100644
View file @
7875287e
File added
out/production/db_java/dao/DBCode.class
0 → 100644
View file @
7875287e
File added
out/production/db_java/dao/MemberDao.class
0 → 100644
View file @
7875287e
File added
out/production/db_java/dao/MemberDaoImpl.class
0 → 100644
View file @
7875287e
File added
out/production/db_java/dto/MemberDto.class
0 → 100644
View file @
7875287e
File added
out/production/db_java/member/MainClass.class
0 → 100644
View file @
7875287e
File added
out/production/db_java/member/Member.class
0 → 100644
View file @
7875287e
File added
src/dao/MemberDao.java
View file @
7875287e
...
...
@@ -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
);
}
src/dao/MemberDaoImpl.java
View file @
7875287e
...
...
@@ -9,7 +9,7 @@ public class MemberDaoImpl implements MemberDao {
private
static
final
String
USERNAME
=
DBCode
.
USERNAME
;
// DBMS접속 시 아이디
private
static
final
String
PASSWORD
=
DBCode
.
PASSWORD
;
// DBMS접속 시 비밀번호
private
static
final
String
URL
=
DBCode
.
URL
;
// DBMS접속할 db명
// 생성자에 연결
public
MemberDaoImpl
()
{
// 디비 연결 부분
...
...
@@ -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
{
...
...
@@ -54,7 +54,7 @@ public class MemberDaoImpl implements MemberDao {
}
catch
(
Exception
e2
)
{
}
}
}
@Override
...
...
@@ -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
src/member/MainClass.java
View file @
7875287e
...
...
@@ -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
());
// 데이터 수정
}
}
src/member/Member.java
View file @
7875287e
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment