PDA

View Full Version : Problem to Dynamic Connect to postgreSQL



whiteboy
05-02-2012, 09:55 PM
Hi everyone. I'm newbie in android. I've dynamic connected completely to postgreSQL in code below:


EditText Address, Port, Database, User, Pass;
Connection connection = null;

public boolean get_connection(){

String address, port, database, user, pass;
address = Address.getText().toString();
port = Port.getText().toString();
Database = Database.getText().toString();
user = User.getText().toString();
pass = Pass.getText().toString();

try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
return false;
}



String url = "jdbc:postgresql://" + address + ":" + port + "/" + database;

try {
connection = DriverManager.getConnection(url, user, pass);

} catch (java.sql.SQLException e) {
e.printStackTrace();
return false;
}
return true;
}


I don't know how to hold that connection information to use for many others activities-java class(EX: for each time one Activity want to connect to load data can use that connection information). Thank in advance.

UltraDroid
05-02-2012, 10:20 PM
Hello whiteboy, and welcome to the forum! :)

cali
05-03-2012, 12:31 AM
Can't help you with the task at hand, but can welcome you to the site! :android-dance:

ebookren
08-30-2012, 07:38 AM
I notice you use the same String names, one uppercase one lower. Your Database= Database Should be database=Database.getText().toString()

Chris

Sent from my Nexus 7 using Android.net