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
2fb99fe8
Commit
2fb99fe8
authored
Dec 02, 2021
by
Deokhyun Lee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added private java file and made it untracked
parent
6fb35deb
Pipeline
#2102
canceled with stages
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
20 deletions
+98
-20
.gitignore
.gitignore
+2
-1
db_java.iml
db_java.iml
+11
-0
DBCode.java
src/dao/DBCode.java
+7
-0
MemberDaoImpl.java
src/dao/MemberDaoImpl.java
+78
-19
No files found.
.gitignore
View file @
2fb99fe8
...
@@ -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
...
...
db_java.iml
0 → 100644
View file @
2fb99fe8
<?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
src/dao/DBCode.java
0 → 100644
View file @
2fb99fe8
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명
}
src/dao/MemberDaoImpl.java
View file @
2fb99fe8
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 (?, ?, ?)"
;
PreparedStatement
pstmt
=
null
;
try
{
pstmt
=
conn
.
prepareStatement
(
sql
);
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
(
"데이터 삽입 성공!"
);
}
}
@Override
}
catch
(
Exception
e
)
{
public
MemberDto
selectOne
(
int
n
)
{
System
.
out
.
println
(
"데이터 삽입 실패!"
);
// TODO Auto-generated method stub
}
finally
{
return
null
;
try
{
if
(
pstmt
!=
null
&&
!
pstmt
.
isClosed
())
{
pstmt
.
close
();
}
}
catch
(
Exception
e2
)
{
}
}
}
@Override
public
ArrayList
<
MemberDto
>
selectAll
()
{
// TODO Auto-generated method stub
return
null
;
}
}
@Override
@Override
public
void
update
(
MemberDto
dto
)
{
public
ArrayList
<
MemberDto
>
selectAll
()
{
// TODO Auto-generated method stub
ArrayList
<
MemberDto
>
list
=
new
ArrayList
<
MemberDto
>();
// 데이터 담을 그릇
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
);
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"select 메서드 예외발생"
);
}
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);
// }
}
}
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