SAK }‘ŠÙ

SAK Streets ƒƒCƒ“ƒXƒgƒŠ[ƒg }‘ŠÙEƒJƒtƒF ˆê—— SAK Streets ŒŸõ
| VB | SQL | Perl | PHP | ASP | JSP | C | PC | HP | FAQ | ƒtƒŠ[ƒ\ƒtƒg |

PostgreSQL + ServletAJSP •Ò3 - JSP JDBC ƒAƒNƒZƒXAexecuteQuery

¡PostgreSQL + JDBCAJAVA Server Page(JSP) ƒAƒNƒZƒX

  EƒeƒXƒg—p‚̃e[ƒuƒ‹‚ð쬂·‚éB

create table testm (
  key char(8),
  data1 int8,
  data2 int8,
  data3 int8
);

insert into testm values ('a001', 1, 2, 3);
insert into testm values ('b002', 10, 20, 30);
insert into testm values ('c003', 100, 200, 300);

commit;

¡PostgreSQL + JDBCAJAVA Server Page(JSP) ƒAƒNƒZƒXƒeƒXƒg

  EJAVA Server Page(JSP) ‚©‚çAJDBC ‚Å PostgreSQL ‚ɃAƒNƒZƒX‚·‚é‚É‚ÍA
    ŽŸ‚̂悤‚É‚·‚éB

<%@ page import="java.util.*,java.sql.*;" contentType="text/html; charset=Shift_JIS"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<TITLE>JAVA Server Page(JSP) - PostgreSQL JDBC Test</TITLE>
</HEAD>
<BODY>
<P>JAVA Server Page(JSP) - PostgreSQL JDBC Test</P>
<%

  try {

    // PostgreSQL JDBC ƒhƒ‰ƒCƒoƒ[ƒh
    Class.forName("org.postgresql.Driver");

    // PostgreSQL JDBC Ú‘±
    String dsn = "jdbc:postgresql://sak-design:5432/sak?user=sak&password=sak";
    Connection cn = DriverManager.getConnection(dsn);

    // PostgreSQL JDBC –â‚¢‡‚킹 SQL ì¬
    String sql = "select * from testm";
    Statement st = cn.createStatement();

    // PostgreSQL JDBC ƒŒƒR[ƒhƒZƒbƒgƒI[ƒvƒ“
    ResultSet rs = st.executeQuery(sql);

    // PostgreSQL JDBC ƒŒƒR[ƒhƒZƒbƒgƒŠ[ƒh
    while (rs.next()) {
      out.println("<P>" + rs.getString(1) + "</P>");
    }

    // PostgreSQL JDBC ƒŒƒR[ƒhƒZƒbƒgƒNƒ[ƒY
    rs.close();

    // PostgreSQL JDBC ƒXƒe[ƒgƒƒ“ƒgƒNƒ[ƒY
    st.close();

    // PostgreSQL JDBC Ú‘±ƒNƒ[ƒY
    cn.close();

  }
  catch (Exception e) {

    // ƒGƒ‰[ˆ—
    out.println("<P>error</P>");

  }

%>
</BODY>
</HTML>

  EJSP(test_postgresql.jsp) ‚ÍAƒ\[ƒX‚»‚Ì‚à‚Ì‚ð
    /jakarta-tomcat-3.3.1/webapps/sak/jsp/ ‚Ì’†‚É”z’u‚µA
    ƒuƒ‰ƒEƒU‚æ‚èAŽŸ‚Ì URL ‚ÅŽÀs‚·‚éB

http://sak-design:8080/sak/jsp/test_postgresql.jsp

¡PostgreSQL •ÒAJAVA ServletAJSP •ÒŽ‘—¿
¡MySQL •ÒŽ‘—¿
¡SQL Šî‘b•ÒŽ‘—¿
¡SQL Šî‘bŽÀ’n•ÒŽ‘—¿
¡SQL ƒ`ƒ…[ƒjƒ“ƒO•ÒŽ‘—¿
¡Oracle PL/SQL •ÒŽ‘—¿
| VB | SQL | Perl | PHP | ASP | JSP | C | PC | HP | FAQ | ƒtƒŠ[ƒ\ƒtƒg |

SAK Streets ƒƒCƒ“ƒXƒgƒŠ[ƒg }‘ŠÙEƒJƒtƒF ˆê—— SAK Streets ŒŸõ



Copyright (C) 1999-2024 Y.SAK