From: | "Dave Cramer" <Dave(at)micro-automation(dot)net> |
---|---|
To: | "'Andres Davila'" <adavila0026(at)yahoo(dot)com>, <pgsql-jdbc(at)postgresql(dot)org> |
Subject: | Re: Problem connecting by JDBC with a SERVLET |
Date: | 2002-02-28 23:54:56 |
Message-ID: | 010401c1c0b3$53211300$8201a8c0@inspiron |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
Andres,
What is the error you get back? Did you put the jdbc jar into the
webapp's lib directory?
Dave
-----Original Message-----
From: pgsql-jdbc-owner(at)postgresql(dot)org
[mailto:pgsql-jdbc-owner(at)postgresql(dot)org] On Behalf Of Andres Davila
Sent: Thursday, February 28, 2002 6:46 PM
To: pgsql-jdbc(at)postgresql(dot)org
Subject: [JDBC] Problem connecting by JDBC with a SERVLET
I try to access a database on a Linux server, with
Apache, Tomcat & Postgres.
The servlet should connect to the database, make a
select and display the results in a webpage
My code is the following:
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try {
String database = "intvuelos";
String username = "nobody";
String password = "";
Class.forName("org.postgresql.Driver");
con =
DriverManager.getConnection("jdbc:postgresql://10.65.28.12/invuelos",
username, password);
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT numeroempleado,
origen, destino FROM viajes");
out.println("<html><head><title>Consulta de
Datos</title></head>");
out.println("<body>");
out.println("<ul>");
while(rs.next()){
out.println("<li>"+
rs.getString("numeroempleado") + " " +
rs.getString("nombre") + " " +
rs.getString("apellidos"));
}
out.println("</ul>");
out.println("</body></html>");
}
catch(ClassNotFoundException e){
out.println("Couldn't load database driver: " + e.getMessage());
}
catch(SQLException e){ out.println("SQLException
caught: " + e.getMessage());
}
finally{
try{
if(con !=null) con.close();
}
catch (SQLException ignored){ }
}
}
}
****
Please help me if you can
__________________________________________________
Do You Yahoo!?
Yahoo! Greetings - Send FREE e-cards for every occasion!
http://greetings.yahoo.com
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?
From | Date | Subject | |
---|---|---|---|
Next Message | Paulo Delgado | 2002-02-28 23:59:12 | Re: Problem connecting by JDBC with a SERVLET |
Previous Message | Andres Davila | 2002-02-28 23:46:27 | Problem connecting by JDBC with a SERVLET |