Problem connecting by JDBC with a SERVLET
Problem connecting by JDBC with a SERVLET
От:
Andres Davila <adavila0026@yahoo.com>
Дата:
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("Consulta de
Datos");
out.println("");
out.println("- ");
while(rs.next()){
out.println("
- "+ rs.getString("numeroempleado") + " " + rs.getString("nombre") + " " + rs.getString("apellidos")); } out.println("
Re: Problem connecting by JDBC with a SERVLET
От:
"Dave Cramer" <Dave@micro-automation.net>
Дата:
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@postgresql.org
[mailto:pgsql-jdbc-owner@postgresql.org] On Behalf Of Andres Davila
Sent: Thursday, February 28, 2002 6:46 PM
To: pgsql-jdbc@postgresql.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("Consulta de
Datos");
out.println("");
out.println("- ");
while(rs.next()){
out.println("
- "+ rs.getString("numeroempleado") + " " + rs.getString("nombre") + " " + rs.getString("apellidos")); } out.println("
Re: Problem connecting by JDBC with a SERVLET
От:
Paulo Delgado <pdelgado@pasaportevip.com>
Дата:
Andres, which error message do you get? (it would help a lot)
Si quieres, puedes escribirme en español, directamente, no a la lista, no creo que les guste =)
On Thu, 28 Feb 2002 15:46:27 -0800 (PST)
Andres Davila wrote:
> 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("Consulta de
> Datos");
> out.println("");
>
> out.println("- ");
>
> while(rs.next()){
>
> out.println("
- "+ > rs.getString("numeroempleado") + " " + > rs.getString("nombre") + " " + > rs.getString("apellidos")); > > } > out.println("