プロが教えるわが家の防犯対策術!

Vine Linux2.6, Tomcat5, Postgresql7.4.3の環境で、
簡単なDBへアクセスのJspを作りましたが、実行したら、次のエラーができましたが、解決方法を
教えてください。
JSP File:
<HTML>
<HEAD><TITLE>User List</TITLE></HEAD>
<BODY>
<%@ page import="java.sql.*" %>
<TABLE BORDER=1 width="75%">
<TR><TH>UID</TH><TH>Password</TH></TR>
<%
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
Class.forName("org.postgresql.Driver").newInstance();
conn =
DriverManager.getConnection("jdbc:postgresql://xxx.xxxx.xx.xx:8080/webshop","postgres","xxxx");
st = conn.createStatement();
rs = st.executeQuery("select * from tbllogin");
while(rs.next()) {
%>
<TR><TD><%= rs.getString("fldlogid") %></TD>
<TD><%= rs.getString("fldpwd") %></TD></TR>
<%
}
%>
</TABLE>
<%
} catch (Exception ex) {
ex.printStackTrace();
%>
</TABLE>
Ooops, something bad happened:
<%
} finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (conn != null) conn.close();
}
%>
</BODY>
</HTML>

Tomcat5のログcatalina.out:
org.postgresql.util.PSQLException: The backend has broken the connection. Possibly the action you have attempted has caused it to close.
at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:168)
at org.postgresql.jdbc1.AbstractJdbc1Connection.openConnectionV3(AbstractJdbc1Connection.java:291)
.....

A 回答 (1件)

パッと見ただけですが、下記のところが怪しいかと。



-----------------------------------------------
DriverManager.getConnection("jdbc:postgresql://xxx.xxxx.xx.xx:8080/webshop","postgres","xxxx");
-----------------------------------------------

この部分は、

jdbc:postgresql://(PostgreSQLのホスト名orIPアドレス):(PostgreSQLのポート番号)/(database名)

という書式です。
TomcatとPostgreSQLが動いているサーバが同じであれば、ホスト名の部分は“localhost”になります。また、PostgreSQLのポート番号はデフォルトで5432です。おそらく、8080はTomcatのポート番号ではないでしょうか。
ポート番号の後ろにはデータベース名が入りますが、“webshop”であっていますでしょうか。

TomcatとPostgreSQLが動いているサーバが同じで、PostgreSQLのポート番号がデフォルトのままで、データベース名が“webshop”とすると下記の様になると思います。

-----------------------------------------------
DriverManager.getConnection("jdbc:postgresql://localhost:5432/webshop");
-----------------------------------------------

参考URL:http://www.postgresql.jp/document/pg743doc/html/ …
    • good
    • 0
この回答へのお礼

すごいでござる。
どうも、ありがとうございます。

お礼日時:2004/08/18 15:06

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!