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 + ServletAJSP •Ò3 - JSP JDBC ƒAƒNƒZƒXAexecuteQuery

¡PostgreSQL + JDBCAJAVA 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 + JDBCAJAVA 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 ServletAJSP •ÒŽ‘—¿
¡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-2017 Y.SAK