pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
simple JDBC --> can't get started
5+ messages / 4 participants
[nested] [flat]

* simple JDBC --> can't get started
@ 1998-07-27 05:15  Yang Su <yangsu@inkle.cs.iastate.edu>
  0 siblings, 1 reply; 5+ messages in thread

From: Yang Su @ 1998-07-27 05:15 UTC (permalink / raw)
  To: pgsql-interfaces


I have a simple test.java which tries to connect to a database I have
created, my user name is "yangsu" which is created by "createuser yangsu"
My db_hba.conf has only the following lines:

local        all                                         trust
host         all         127.0.0.1     255.255.255.255   trust     
host         all         129.186.68.160  255.255.255.255 trust

My machine name is inkle.cs.iastate.edu(ip 129.186.68.160), my execution
of "java test" yields:

Class.forName OK!
java.sql.SQLException: Connection failed: java.net.ConnectException: Connection refused

What is the error?(what causes the error?) Thanks for any suggestions.

yang
http://www.cs.iastate.edu/~yangsu/


Following is the test.java:

import java.io.*;
import java.net.*;
import java.sql.*;

public class test{

   public static void main(String args[]){
        try{
                Class.forName("postgresql.Driver");
                System.out.println("Class.forName OK!");

                String url="jdbc:postgresql://inkle.cs.iastate.edu/test";
                String usr="yangsu";
                String pwd="";

                Connection db = DriverManager.getConnection(url, usr, pwd);
                if(db != null){
                        System.out.println("Connected to db");
                }else{
                        System.out.println("Can't connect to db");
                }

                Statement st = db.createStatement();
                ResultSet rs = st.executeQuery("select * from classmate");

                while(rs.next()){
                        System.out.println(rs.getString("name"));
                        System.out.println(rs.getBoolean("sex"));
                        System.out.println(rs.getInt("age"));
                }
        }catch(Exception e){
                System.out.println(e.toString());
        }
   }

}






^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* RE: [INTERFACES] simple JDBC --> can't get started
@ 1998-07-27 05:35  Michael Yeung <michaely@alphanet.net.au>
  0 siblings, 0 replies; 5+ messages in thread

From: Michael Yeung @ 1998-07-27 05:35 UTC (permalink / raw)
  To: 'yangsu@flash.cs.iastate.edu' <yangsu@flash.cs.iastate.edu>; +Cc: pgsql-interfaces

HI,

What have u entered for your password entry.

For most JDBC driver, you have to enter the password for the user that connected to the dB Server.

You haven't enter the password, have you ?

cheers,
Michael
-----Original Message-----
From:	Yang Su [SMTP:yangsu@inkle.cs.iastate.edu]
Sent:	Monday, July 27, 1998 3:16 PM
To:	pgsql-interfaces@postgreSQL.org
Subject:	[INTERFACES] simple JDBC --> can't get started


I have a simple test.java which tries to connect to a database I have
created, my user name is "yangsu" which is created by "createuser yangsu"
My db_hba.conf has only the following lines:

local        all                                         trust
host         all         127.0.0.1     255.255.255.255   trust     
host         all         129.186.68.160  255.255.255.255 trust

My machine name is inkle.cs.iastate.edu(ip 129.186.68.160), my execution
of "java test" yields:

Class.forName OK!
java.sql.SQLException: Connection failed: java.net.ConnectException: Connection refused

What is the error?(what causes the error?) Thanks for any suggestions.

yang
http://www.cs.iastate.edu/~yangsu/


Following is the test.java:

import java.io.*;
import java.net.*;
import java.sql.*;

public class test{

   public static void main(String args[]){
        try{
                Class.forName("postgresql.Driver");
                System.out.println("Class.forName OK!");

                String url="jdbc:postgresql://inkle.cs.iastate.edu/test";
                String usr="yangsu";
                String pwd="";

                Connection db = DriverManager.getConnection(url, usr, pwd);
                if(db != null){
                        System.out.println("Connected to db");
                }else{
                        System.out.println("Can't connect to db");
                }

                Statement st = db.createStatement();
                ResultSet rs = st.executeQuery("select * from classmate");

                while(rs.next()){
                        System.out.println(rs.getString("name"));
                        System.out.println(rs.getBoolean("sex"));
                        System.out.println(rs.getInt("age"));
                }
        }catch(Exception e){
                System.out.println(e.toString());
        }
   }

}






^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* RE: [INTERFACES] simple JDBC --> can't get started
@ 1998-07-27 06:35  Mikael Hammarin <mikael.hammarin@dc.etx.ericsson.se>
  0 siblings, 0 replies; 5+ messages in thread

From: Mikael Hammarin @ 1998-07-27 06:35 UTC (permalink / raw)
  To: 'yangsu@flash.cs.iastate.edu' <yangsu@flash.cs.iastate.edu>; pgsql-interfaces

I'd guess you probably haven't started "postmaster" with -i,
which means it runs only through unix local domain sockets.

Check "man postmaster" for more info.

Cheers
//Mike

> -----Original Message-----
> From: Yang Su [mailto:yangsu@inkle.cs.iastate.edu]
> Sent: Monday, July 27, 1998 7:16 AM
> To: pgsql-interfaces@postgreSQL.org
> Subject: [INTERFACES] simple JDBC --> can't get started
> 
> 
> 
> I have a simple test.java which tries to connect to a database I have
> created, my user name is "yangsu" which is created by 
> "createuser yangsu"
> My db_hba.conf has only the following lines:
> 
> local        all                                         trust
> host         all         127.0.0.1     255.255.255.255   trust     
> host         all         129.186.68.160  255.255.255.255 trust
> 
> My machine name is inkle.cs.iastate.edu(ip 129.186.68.160), 
> my execution
> of "java test" yields:
> 
> Class.forName OK!
> java.sql.SQLException: Connection failed: 
> java.net.ConnectException: Connection refused
> 
> What is the error?(what causes the error?) Thanks for any suggestions.
> 
> yang
> http://www.cs.iastate.edu/~yangsu/
> 
> 
> Following is the test.java:
> 
> import java.io.*;
> import java.net.*;
> import java.sql.*;
> 
> public class test{
> 
>    public static void main(String args[]){
>         try{
>                 Class.forName("postgresql.Driver");
>                 System.out.println("Class.forName OK!");
> 
>                 String 
> url="jdbc:postgresql://inkle.cs.iastate.edu/test";
>                 String usr="yangsu";
>                 String pwd="";
> 
>                 Connection db = 
> DriverManager.getConnection(url, usr, pwd);
>                 if(db != null){
>                         System.out.println("Connected to db");
>                 }else{
>                         System.out.println("Can't connect to db");
>                 }
> 
>                 Statement st = db.createStatement();
>                 ResultSet rs = st.executeQuery("select * from 
> classmate");
> 
>                 while(rs.next()){
>                         System.out.println(rs.getString("name"));
>                         System.out.println(rs.getBoolean("sex"));
>                         System.out.println(rs.getInt("age"));
>                 }
>         }catch(Exception e){
>                 System.out.println(e.toString());
>         }
>    }
> 
> }
> 
> 
> 
> 



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [INTERFACES] simple JDBC --> can't get started
@ 1998-07-27 09:46  Peter T Mount <peter@retep.org.uk>
  parent: Yang Su <yangsu@inkle.cs.iastate.edu>
  0 siblings, 0 replies; 5+ messages in thread

From: Peter T Mount @ 1998-07-27 09:46 UTC (permalink / raw)
  To: yangsu@flash.cs.iastate.edu; +Cc: pgsql-interfaces

On Mon, 27 Jul 1998, Yang Su wrote:

>                 String usr="yangsu";
>                 String pwd="";

Even when using trust, the password must have something in it, otherwise
JDBC will not start. It cannot be null, nor "". 

However trust (and ident) doesn't need the password to be defined in the
database.

-- 
Peter T Mount peter@retep.org.uk or petermount@earthling.net
Main Homepage: http://www.retep.org.uk
************ Someday I may rebuild this signature completely ;-) ************
Work Homepage: http://www.maidstone.gov.uk Work EMail: peter@maidstone.gov.uk




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: [INTERFACES] simple JDBC --> can't get started
@ 1998-07-27 18:10  Yang Su <yangsu@inkle.cs.iastate.edu>
  0 siblings, 0 replies; 5+ messages in thread

From: Yang Su @ 1998-07-27 18:10 UTC (permalink / raw)
  To: Michael Yeung <michaely@alphanet.net.au>; +Cc: pgsql-interfaces


Thanks, I have got the sample work. I checked my program and found the following
should be added:
the proper port
the -i option in starting postmaster

One more question, how do I assign (user,passwd) to each database I own, or
I can just assign one (user,passwd) for all the databases I own? Please give
me an example show me how.

Thanks.

yang




^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~1998-07-27 18:10 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1998-07-27 05:15 simple JDBC --> can't get started Yang Su <yangsu@inkle.cs.iastate.edu>
1998-07-27 09:46 ` Peter T Mount <peter@retep.org.uk>
1998-07-27 05:35 RE: [INTERFACES] simple JDBC --> can't get started Michael Yeung <michaely@alphanet.net.au>
1998-07-27 06:35 RE: [INTERFACES] simple JDBC --> can't get started Mikael Hammarin <mikael.hammarin@dc.etx.ericsson.se>
1998-07-27 18:10 Re: [INTERFACES] simple JDBC --> can't get started Yang Su <yangsu@inkle.cs.iastate.edu>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox