작성중인 문서입니다!

2016. 9. 7. 17:55프로그래밍/jsp

반응형

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8" import="java.sql.*"%>

<!DOCTYPE html>

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

<link rel="stylesheet" type="text/css" href="comm.css"></head><body>

<% String dno = request.getParameter("dno");

String driver = "com.mysql.jdbc.Driver";

String url = "jdbc:mysql://127.0.0.1:3306/test?useSSL=false";

String sql = "select * from division where dno="+dno;

Connection conn=null; Statement stmt=null; ResultSet rs=null;

String dname="", phone = "", position = "";

try { Class.forName(driver);

conn = DriverManager.getConnection(url,"root","mysql");

stmt = conn.createStatement();

rs = stmt.executeQuery(sql);

rs.next();

dname = rs.getString(2); 

phone = rs.getString(3);

position = rs.getString(4);

}catch(Exception e) { System.out.println(e.getMessage());

}finally {

if (rs != null) rs.close();

if (stmt != null) stmt.close();

if (conn != null) conn.close();

}

%>

<form action="myUpdate.jsp">

<table>

<caption>수정할 정보</caption>

<tr><th>부서코드</th><td><input type="hidden" name="dno" 

value="<%=dno%>"><%=dno%></td></tr>

<tr><th>부서명</th><td><input type="text"" name="dname" 

value="<%=dname%>" required="required"></td></tr>

<tr><th>전화번호</th><td><input type="tel" name="phone" 

value="<%=phone%>" required="required"></td></tr>

<tr><th>근무지</th><td><input type="text" name="position" 

value="<%=position%>" required="required"></td></tr>

<tr><th><input type="submit" value="확인"></th></tr>

</table></form></body></html>




<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8" import="java.sql.*"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title></head><body>

<%

String driver = "com.mysql.jdbc.Driver";

String url = "jdbc:mysql://127.0.0.1:3306/test?useSSL=false";

String dno = request.getParameter("dno");

String dname = request.getParameter("dname");

String phone = request.getParameter("phone");

String position = request.getParameter("position");

Connection conn = null; Statement stmt = null;

String sql = String.format(

"update division set dname='%s',phone='%s',position='%s'"

+ " where dno=%s",dname,phone,position,dno);

try {

Class.forName(driver);

conn = DriverManager.getConnection(url,"root","mysql");

stmt = conn.createStatement();

int result = stmt.executeUpdate(sql);

if (result > 0) response.sendRedirect("MyUpdateSelect.jsp");

else out.println("수정 실패");

}catch(Exception e) { 

System.out.println(e.getMessage());

out.println("수정 실패 ㅠㅠ");

}finally {

if (stmt != null) stmt.close();

if (conn != null) conn.close();

}

%>

</body>

</html>


mydate


<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8" import="java.sql.*,java.util.*,ch10.*"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title></head><body>

<% String driver = "com.mysql.jdbc.Driver";

String url = "jdbc:mysql://127.0.0.1:3306/test?useSSL=false";

String sql = "select * from division order by dno";

List<Division> list = new ArrayList<>();

Connection conn=null; Statement stmt=null; ResultSet rs=null;

try { Class.forName(driver);

conn = DriverManager.getConnection(url,"root","mysql");

stmt = conn.createStatement();

rs = stmt.executeQuery(sql);

while(rs.next()) {

Division dept = new Division();

dept.setDno(rs.getInt("dno"));

dept.setDname(rs.getString("dname"));

dept.setPhone(rs.getString("phone"));

dept.setPosition(rs.getString("position"));

list.add(dept);

}

request.setAttribute("list", list);

RequestDispatcher rd = 

request.getRequestDispatcher("MyUpSelResult.jsp");

rd.forward(request, response);

}catch(Exception e) { System.out.println(e.getMessage());

}finally{

if (rs != null) rs.close();

if (stmt != null) stmt.close();

if (conn != null) conn.close();

}

%>

</body>

</html>


myupsateselect


<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

<link rel="stylesheet" type="text/css" href="comm.css"></head><body>

<table>

<caption>부서 리스트</caption>

<tr><th>부서코드</th><th>부서명</th><th>전화</th><th>근무지</th>

<th>수정여부</th><th>삭제여부</th></tr>

<c:forEach var="d" items="${list }">

<tr><td>${d.dno }</td><td>${d.dname}</td>

<td>${d.phone }</td><td>${d.position }</td>

<td><a href="MyUpdateForm.jsp?dno=${d.dno}">수정</a></td>

<td><a href="MyDelete.jsp?dno=${d.dno}">삭제</a></td></tr>

</c:forEach>

<tr><th colspan="6"><a href="MyDivisionInput.jsp">입력</a> </th></tr>

</table>

</body>

</html>


myselresult


<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

<link rel="stylesheet" href="comm.css" type="text/css">

</head><body><form action="MyDivisionInsert.jsp"><table>

<caption>부서정보 입력</caption>

<tr><th>부서코드</th><td><input type="number" name="dno" 

required="required"></td></tr>

<tr><th>부서명</th><td><input type="text" name="dname" 

required="required"></td></tr>

<tr><th>전화번호</th><td><input type="tel" name="phone" 

required="required" placeholder="xxx-xxxx-xxxx"></td></tr>

<tr><th>근무지</th><td><input type="text" name="position" 

required="required"></td></tr>

<tr><th colspan="2"><input type="submit" value="확인">

</th></tr></table></form>

</body>

</html>



부서정보를 입력 하도록 html화면에서 구현하는 쿼리 


<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8" import="java.sql.*" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title></head><body>

<% String driver = "com.mysql.jdbc.Driver";

String url = "jdbc:mysql://127.0.0.1:3306/test?useSSL=false";

String dno = request.getParameter("dno");

String dname = request.getParameter("dname");

String phone = request.getParameter("phone");

String position = request.getParameter("position");

String sql = String.format(

"insert into division values (%s,'%s','%s','%s')",

dno, dname, phone, position);

Connection conn = null; Statement stmt = null;

try {

Class.forName(driver);

conn = DriverManager.getConnection(url,"root","mysql");

stmt = conn.createStatement();

int result = stmt.executeUpdate(sql);

if (result > 0) response.sendRedirect("MyUpdateSelect.jsp");

else out.println("으이그 또 실패");

}catch(Exception e) {

System.out.println(e.getMessage());

out.println("입력 실패야");

}finally {

if (stmt != null) stmt.close();

if (conn != null) conn.close();

}

%>

</body>

</html>



반응형

'프로그래밍 > jsp' 카테고리의 다른 글

게시판 답글 관련... 작성중  (0) 2016.09.20
html를 이용한 Mysql DB추가  (0) 2016.09.07
html에서 부서코드를 입력받아 Mysql 실행  (0) 2016.09.06
mysql 연동하기  (0) 2016.09.06
피보나치 수열 합산!  (0) 2016.09.01