simple JDBC --> can't get started
simple JDBC --> can't get started
От:
Yang Su <yangsu@inkle.cs.iastate.edu>
Дата:
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());
}
}
}
Re: [INTERFACES] simple JDBC --> can't get started
От:
Peter T Mount <peter@retep.org.uk>
Дата:
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