<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.ResultSet"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
String id = request.getParameter("id");
int pw = Integer.parseInt(request.getParameter("pw"));
try {
Connection con = null;
String dburl = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
String username = "c##jwh";
String password = "1";
con = DriverManager.getConnection(dburl, username, password);
PreparedStatement ps = null;
//String sql = String.format("select * FROM banana WHERE id = '%s' and pw= %d ",id,pw);
//select문 확실하게 밑에 while문까지
String sql = String.format("select count(*) as num from banana WHERE id = '%s' and pw= %d ",id,pw);
ps = con.prepareStatement(sql);
System.out.println(sql);
ResultSet rs = ps.executeQuery();
//boolean isfind = false;
/* while (rs.next()) {
//rs.next쓰는법?
String id1 = rs.getString("id");
int pw1 = rs.getInt("pw");
//하지만 id랑 pw가 맞으면 true
if (id.equals(id1) && pw == pw1) {
isfind = true;
}
} */
rs.next();
int num = rs.getInt("num");
rs.close();
con.close();
/* if (isfind) {
response.sendRedirect("bbb.jsp");
} else {
response.sendRedirect("ccc.jsp");
} */
if(num==1){
response.sendRedirect("bbb.jsp");
}else{
response.sendRedirect("ccc.jsp");
}
} catch (Exception e) {
e.printStackTrace();
//count쓸때는 이것까지 써줘야된다. 확실히 뭔지?
}
%>
</body>
</html>
'비트 장기 > jsp' 카테고리의 다른 글
8/17 jsp 복습 (0) | 2018.08.18 |
---|---|
8/16 (out,) (0) | 2018.08.16 |
8/13 복습 (0) | 2018.08.14 |
8/13 jsp (0) | 2018.08.13 |
8/10 복습 (0) | 2018.08.11 |
댓글