T
Thomas Hoheneder
Hello,
I am new to JDBC and Postgres and I want to get a connection to a Postgres
database from a Java servlet.
I have done the following things.
1) Installed Postgres 8.0 Beta 2
2) Copied the JDBC driver "pg74.215.jdbc3.jar" into the WEB-INF\lib
directory under my application path in Tomcat
3) Added the "pg74.215.jdbc3.jar" to my Eclipse project
4) Created a Java class "DatabaseConnectivityServlet" within my project (see
code below)
I use a Class.forName() and a DriverManager.getConnection() instruction, but
both do not compile well. I am not sure if my arguments to these functions
are right. Of cource, the last two arguments of getConnection() must be the
db user name and password. And template1 is my database name for the first
step.
The main problem now is, that my code doesn't ccompile well, and so I don't
have a connection to the Postgres DB.
Why? What do I have to do now?
Any help to this would be very appreciated. Thanks in advance.
Nice greetings from
Thomas
DatabaseConnectivityServlet.java
-----------------------------------------------
package de.th.test;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class DatabaseConnectivityServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
Class.forName("org.postgresql.Driver");
Connection connection = DriverManager.getConnection("" +
"jdbcostgresql://127.0.0.1:5432/template1", "", "");
}
}
I am new to JDBC and Postgres and I want to get a connection to a Postgres
database from a Java servlet.
I have done the following things.
1) Installed Postgres 8.0 Beta 2
2) Copied the JDBC driver "pg74.215.jdbc3.jar" into the WEB-INF\lib
directory under my application path in Tomcat
3) Added the "pg74.215.jdbc3.jar" to my Eclipse project
4) Created a Java class "DatabaseConnectivityServlet" within my project (see
code below)
I use a Class.forName() and a DriverManager.getConnection() instruction, but
both do not compile well. I am not sure if my arguments to these functions
are right. Of cource, the last two arguments of getConnection() must be the
db user name and password. And template1 is my database name for the first
step.
The main problem now is, that my code doesn't ccompile well, and so I don't
have a connection to the Postgres DB.
Why? What do I have to do now?
Any help to this would be very appreciated. Thanks in advance.
Nice greetings from
Thomas
DatabaseConnectivityServlet.java
-----------------------------------------------
package de.th.test;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class DatabaseConnectivityServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
Class.forName("org.postgresql.Driver");
Connection connection = DriverManager.getConnection("" +
"jdbcostgresql://127.0.0.1:5432/template1", "", "");
}
}