본문 바로가기
프로그래밍/웹 프로그래밍

[JSP] How to use JDBC for PostgreSQL

by 체리 2007. 7. 11.
반응형

I can't  write in korean right now -_-;

1. download jdbc driver from here.
2. Simply you should put the driver in $CATALINA_HOME/webapps/ROOT/WEB-INF/lib.
3. restart your tomcat.

I'll show you simple jsp code.

<%@
page language="java"
contentType="text/html;charset=EUC-KR"
import="java.sql.*"
%>
<%

try{
 String url = "jdbc:postgresql://localhost/databasename";
 String usr = "userid";
 String pwd = "passwd";

 Class.forName("org.postgresql.Driver");
 Connection conn = DriverManager.getConnection(url, usr, pwd);
 Statement stmt = conn.createStatement();
 ResultSet rs = stmt.executeQuery("query made by you");

 while(rs.next())
 {
  out.println(rs.getRow());
  out.println("<br>");
  out.println(rs.getString("uid"));
 }

 rs.close();
 stmt.close();
 conn.close();
} catch (Exception e) {
 out.println(e);
}

%>

반응형

태그

, ,

댓글0