jdbc + postgres

Started by Przemyslaw Bakover 27 years ago4 messagesgeneral
Jump to latest
#1Przemyslaw Bak
przemol@st3.makro.com.pl

Hello,

I have following program:

----------------------- CUT ------------------------
import java.net.URL;
import java.sql.*;

....

String url = "jdbc:postgresql://localhost/store3";
//String url = "jdbc:postgresql:store3";
Connection db;
Statement st;

TillInfo () {
try {
System.err.println ( "Loading driver ..." );
Class.forName ("postgresql.Driver");
} catch (java.lang.ClassNotFoundException e) {
System.err.print ("ClassNotFoundException:");
System.err.println (e.getMessage());
}

try {
System.err.println ( "Connecting ..." );
db = DriverManager.getConnection (url,"przemol","przemol");
System.err.println ( "Preparing statement ..." );
st = db.createStatement ();
System.err.println ( "Executing query ..." );
ResultSet rs = st.executeQuery (query);
if (rs != null) {
....
}
st.close ();
db.close ();
} catch (SQLException ex) {
System.err.println ( "SQLState:" + ex.getSQLState() );
System.err.println ( "Message:" + ex.getMessage() );
System.err.println ( "Vendor:" + ex.getErrorCode() );
}
}

------------------ CUT ------------------

While running I have message:

Loading driver ...
Connecting ...
SQLState:null
Message:Connection failed: java.net.ConnectException: Connection refused
Vendor:0
Exception occurred during event dispatching:
java.lang.ArithmeticException: / by zero
at PanelChart.paint(PanelChart.java:11)
at java.awt.Component.dispatchEventImpl(Component.java:1401)
at java.awt.Component.dispatchEvent(Component.java:1382)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:63)

Could you tell me whats wrong with my program ?
Do I have to change sources ? If so can you tell me how ?
I use jdbc driver from postgres 6.3.2 sources and jdk 1.1.3.
Of course postgres is running :))

przemol

#2Peter T Mount
peter@retep.org.uk
In reply to: Przemyslaw Bak (#1)
Re: [GENERAL] jdbc + postgres

On Tue, 20 Oct 1998, Przemyslaw Bak wrote:

While running I have message:

Loading driver ...
Connecting ...
SQLState:null
Message:Connection failed: java.net.ConnectException: Connection refused

This seems to be the most common problem ;-)

You are not running the backend with the -i arg, which turns on tcp/ip.

Check the FAQ.

Peter

--
Peter T Mount peter@retep.org.uk
Main Homepage: http://www.retep.org.uk
PostgreSQL JDBC Faq: http://www.retep.org.uk/postgres
Java PDF Generator: http://www.retep.org.uk/pdf

#3Przemyslaw Bak
przemol@st3.makro.com.pl
In reply to: Peter T Mount (#2)
Re: [GENERAL] jdbc + postgres

On Tue, 20 Oct 1998, Peter T Mount wrote:

Message:Connection failed: java.net.ConnectException: Connection refused

This seems to be the most common problem ;-)

You are not running the backend with the -i arg, which turns on tcp/ip.

Thank you. Two characters more and everything works great.
I need to come back to basic school ...

Check the FAQ.

Which one: java or postgres ?

przemol

#4Peter T Mount
peter@retep.org.uk
In reply to: Przemyslaw Bak (#3)
Re: [GENERAL] jdbc + postgres

On Wed, 21 Oct 1998, Przemyslaw Bak wrote:

On Tue, 20 Oct 1998, Peter T Mount wrote:

Message:Connection failed: java.net.ConnectException: Connection refused

This seems to be the most common problem ;-)

You are not running the backend with the -i arg, which turns on tcp/ip.

Thank you. Two characters more and everything works great.
I need to come back to basic school ...

Check the FAQ.

Which one: java or postgres ?

The Postgresql jdbc one...

--
Peter T Mount peter@retep.org.uk
Main Homepage: http://www.retep.org.uk
PostgreSQL JDBC Faq: http://www.retep.org.uk/postgres
Java PDF Generator: http://www.retep.org.uk/pdf