import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class DBConnectionTest extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
res.setContentType("text/html; charset=euc-kr");
PrintWriter out = res.getWriter();
try {
// 오라클 드라이버를 Load 한다
Class.forName(“oracle.jdbc.driver.OracleDriver");
// 데이타 베이스에 접속을 한다.
con = DriverManager.getConnection(
"jdbc:oracle:thin:@127.0.0. 1:1521:ahah", "scott", "tiger");
// Statement object를 생성한다.
stmt = con.createStatement();
// ResultSet을 얻기위해 SQL query를 실행한다.
rs = stmt.executeQuery("SELECT NAME, PHONE FROM EMPLOYEES");
// 결과 출력
out.println("<HTML><HEAD><TITLE>Phonebook</TITLE></HEAD>");
out.println("<BODY>");
out.println("<UL>");
while(rs.next()) {
out.println("<LI>" + rs.getString("name") + " " + rs.getString("phone")); //rs.getString(1), rs.getString(2)등 숫자도 가능
}
out.println("</UL>");
out.println("</BODY></HTML>");
}
catch(ClassNotFoundException e) {
out.println("Couldn't load database driver: " + e.getMessage());
}
catch(SQLException e) {
out.println("SQLException caught: " + e.getMessage());
}
finally {
// 언제나 데이타 베이스 연결을 종료한다.
try {
if (con != null) con.close();
}
catch (SQLException ignored) { }
}
}
12-27 | 1678 | |||
12-11 | 1195 | |||
53 | 03-15 | 957 | ||
52 | 01-31 | 1115 | ||
51 | 01-31 | 874 | ||
50 | 01-31 | 808 | ||
49 | 01-19 | 1093 | ||
48 | 01-11 | 985 | ||
47 | 01-03 | 1479 | ||
46 | 12-27 | 1678 | ||
45 | 12-19 | 1222 | ||
44 | 12-14 | 1216 | ||
43 | 12-11 | 1195 | ||
42 | 12-09 | 966 | ||
41 | 12-01 | 1138 | ||
40 | 12-01 | 1372 | ||
39 | 12-01 | 856 |
댓글 없음:
댓글 쓰기