On Dec 15, 11:12 am, "John B. Matthews" <nos...@nospam.invalid> wrote:
In article
<55efcbf6-3ab4-4085-adcd-6d901d739...@v7g2000pro.googlegroups.com>,
Jerim <wyo...@gmail.com> wrote:
[...]
package Program;
import java.sql.*;
public class Database {
public void DBConnect() {
Connection conn = null;
[...]
}
public void DBClose(String conn) {
[...]
}
I can connect to the database just fine. My question, is that when
calling the DBClose() method, how do I pass along the connection I
created when I called DBConnect()? I have a sample program setup that
opens the database connection and then tries to close it.
package Program;
public class Processing {
public void Login(String Username, String Password){
Database dbconnection = new Database();
dbconnection.DBConnect();
//Database operations go here
dbconnection.DBClose(conn);
}
}
I see that conn has package-private access, so Database.conn would refer
to the Connection created by DBConnect():
<http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html>
Alternatives might include these:
1) public Connection DBConnect() { ... return conn; }
2) public Connection getConnection() { ... return conn; }
Conventionally, package names have lower case names:
<http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html>
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
Such a simple solution that I overlooked. I appreciate that very much.