0

please help with my connection i'm getting error("exception: org.postgresql.util.PSQLException: The connection attempt failed.The connection attempt failed.")
this is my code..

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ page language="java" import="java.sql.*"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html:html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>List of Employee</title>
</head>
<body>
<table border="1" cellpadding="1" cellspacing="1" align="center">
<tr>
<th>Test Connection</th>
</tr>
<tr>
<td>Hooray! We connected to the database!</td>
</tr>
<tr>
<td><a href="pages/MainForm.jsp"> <html:button value="Back to Main Menu" property="back"/> </a></td>
</tr>
<tr>
<td><html:button value="Test Connection" property="Sample"/></td>
</tr>
<%
        try {
        Class.forName("org.postgresql.Driver");
                Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:8080/Employee", "rtz_jhay","kudeta7");
            Statement stmt = conn.createStatement();
            ResultSet rs;

            rs = stmt.executeQuery("SELECT * FROM Empinfo");
            out.println( "<table border=1>" );
            out.println("<table border=1><tr bgcolor=yellow><th>Nr</th><th>Product</th><th>Type</th><th>Amount</th><th>Price</th></tr>");

            while ( rs.next() ) {
                String a = rs.getString("id");
                String b = rs.getString("name");

                out.println("<tr><td>"+a+"</td><td>"+b+"</td></tr>" );
            }
                out.println( "</table>" );

                conn.close();

        } catch (ClassNotFoundException e) {
            out.println("<h1>Class not found:" + e + e.getMessage() + "</h1>" );
        } catch (Exception e) {
            out.println( "<h1>exception: "+e+e.getMessage()+"</h1>" );
        }
%>


</table>
</body>
</html:html>

Edited by mike_2000_17: Fixed formatting

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by agent7
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.