20220321 º¹½À
More information <- ÀÚ¼¼ÇÑ ±¸Á¶ ¹× ¹®¹ý (Address Management System)
1. Java Build Path -> Classpath (Add External JARs..) -> mysql-connector-java-8.0.27.jar Ãß°¡
2. Deployment Assembly -> Add -> Java Build Path Entries -> mysql-connector-java-8.0.27.jar Ãß°¡
Connection conn=null;
PreparedStatement pstmt=null;
String jdbc_driver = "com.mysql.cj.jdbc.Driver";
String jdbc_url="jdbc:mysql://127.0.0.1:3306/db53";
String id="root";
String pw="123456";
try {
Class.forName(jdbc_driver);
conn=DriverManager.getConnection(jdbc_url, id, pw);
} catch (ClassNotFoundException e) {
e.getStackTrace();
} catch (SQLException e) {
e.getStackTrace();
}
CREATE TABLE `addrbook` (
`ab_id` int(11) NOT NULL AUTO_INCREMENT,
`ab_name` varchar(15) NOT NULL,
`ab_email` varchar(50) DEFAULT NULL,
`ab_comdept` varchar(20) NOT NULL,
`ab_birth` varchar(10) NOT NULL,
`ab_tel` varchar(20) DEFAULT NULL,
`ab_memo` varchar(100) DEFAULT NULL,
PRIMARY KEY (`ab_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
show databases;
use DB;
show tables;
select * from TB;
Truncate => truncate addrbook;
Insert => insert into addrbook(field1, field2, field3) values(?,?,?)
Select => select * from addrbook where field=value
Update => update addrbook set field1=value where field2=value
Delete => delete from addrbook where field=value
ResultSet rs = pstmt.executeQuery();
pstmt.executeUpdate();
rs.next();
rs.getInt / getString ( parameterIndex, value );
rs.setInt / setString ( parameterIndex, value );
int ab_id;
String ab_name;
String ab_email;
String ab_tel;
String ab_birth;
String ab_comdept;
String ab_memo;
void connect(){
}
void disconnect(){
}
void updateDB(){
}
void deleteDB(){
}
void insertDB(){
}
void selectDB(){
}
void getDB(){
}
<% request.setCharacterEncoding("UTF-8"); %> -> ÀÎÄÚµù
<% pageContext.forward("ab_ctl.jsp?command=select"); %> -> ÆäÀÌÁö À̵¿ ¹× command °ª ¼³Á¤
<%@ page import="java.util.*" %> -> import
<jsp:useBean id="ab" class="addrbook.AddrBean"/> -> °´Ã¼ »ý¼º
<jsp:setProperty property="*" name="abk" /> -> °´Ã¼ÀÇ º¯¼ö°ª ¼³Á¤
<form method="post" action="ab_ctl.jsp" name="form1"> -> form À̵¿ / hiddenÀ¸·Î command °ª ¼³Á¤ / onClickÀ¸·Î ½ºÅ©¸³Æ® ÇÔ¼ö ½ÇÇà
<input type="hidden" name="command" value="update">
<input type="submit" value="[ Update ]"> <input type="button" value="[ Delete ]" onClick="delCheck()">
</form>
<head>
<script type="text/javascript">
function delCheck(){
result = confirm('Are you sure you want to delete ?');
if(result == true)
{
document.form1.command.value="delete"; -> form1 ¹®¼ÀÇ command °ªÀ» ¼³Á¤
document.form1.submit();
} else {
return;
}
}
</script>
</head>