Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
PostgreSQL/Eclipse/Tomcat - How to connect to DB?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Thomas Hoheneder, post: 587755"] 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("" + "jdbc:postgresql://127.0.0.1:5432/template1", "", ""); } } [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
PostgreSQL/Eclipse/Tomcat - How to connect to DB?
Top