error accesing postgresql manually from netbeans
Subject: error accesing postgresql manually from netbeans
Newsgroups: gmane.comp.java.ide.netbeans.user
Date: 2008-09-06 22:38:29 GMT
I have the following code to connect to postgresql
protected boolean Open(){
boolean aResult = false;
try{
/*
//String url = "jdbc:postgresql://" + _host + "/" + _database;
String url = "jdbc:postgresql://" + _host + ";user=" + _userName + ";password=" + _userPassword;
Class.forName ("org.postgresql.Driver").newInstance();
//Connection PostgreSQLConnector = DriverManager.getConnection (url, _userName, _userPassword);
Connection PostgreSQLConnector = DriverManager.getConnection (url);
_connectionObject = PostgreSQLConnector;
aResult = true;
*/
//String url = "jdbc:postgresql://" + _host + ":" + _port + "/" + _database;
String url = "jdbc:postgresql://" + _host + ":" + _port + "/" + _database +
"?user=" + _userName + "&password=" + _userPassword;
/*
Properties props = new Properties();
props.setProperty("user",_userName);
props.setProperty("password",_userPassword);
props.setProperty("ssl","false");
*/
Connection PostgreSQLConnector = DriverManager.getConnection(url);
_connectionObject = PostgreSQLConnector;
aResult = true;
}
catch (Exception e){
}
return aResult;
}
In comments you can see the different ways I tried , but basically I'm able to connect without any exception generated.
I want to execute a simple query to the server that returns me a value
public String Query_Execute_GetValue(String query){
String aResult = null;
try{
Connection ServerConnector = (Connection)_connectionObject;
Statement statement = ServerConnector.createStatement();
ResultSet RecordSet = statement.executeQuery(query);
if (RecordSet.first())
aResult = new String(RecordSet.getString("pk"));
}
catch (Exception e){
}
return aResult;
}
the line
if (RecordSet.first()) always is false even when the simple query I tested with another client and return me the right value.
Thanks in advance for any help.
Enediel
Get news, entertainment and everything you care about at Live.com. Check it out!
RSS Feed