[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cobalt-developers] Java Server Application using PostgreSQL: Success Stories?



got it here. A program i wrote to debug my connection:

stick in your own ip, username and password, this uses the
"org.sourceforge.jxdbcon.JXDBConDriver" driver, you'll need to use that one
or change the Class.forName it uses. Search sourceforge for this if you want
to use this driver.

There's lots of output, hopfully this will give a good indication where the
problem is, this is what i used to debug my own connection.

on a good day it'll print out the first column in the user database (bunch
of numbers... but shows the connection worked).

here's the src, save it as postgres.java and run "javac postgres.java" then
"java postgres"
i'm sure you know that already... : ¬)

let me knoe how it goes.
Paul.



import java.sql.*;
public class postgres {
public static void main(String[] args) {
System.out.println("trying...");
try {
String url = new String("jdbc:postgresql:net//123.123.123.123/5583/cobalt");
String usr = new String("user");
String pwd = new String("password"); //postgres usr/password
System.out.println("finding driver...");
Class.forName("org.sourceforge.jxdbcon.JXDBConDriver");
System.out.println("creating driverManager...");
Connection db = DriverManager.getConnection(url,usr,pwd);
System.out.println("creating statement...");
Statement st = db.createStatement();
System.out.println("executing query...");
ResultSet rs = st.executeQuery("select * from users");
System.out.println("looping data...");
while(rs.next()) {
System.out.print("Column 1 returned ");
System.out.println(rs.getString(1));
}
System.out.println("loop finished, closing connection");
rs.close();
st.close();