File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Easiest way to pass a username to a class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Easiest way to pass a username to a class" Watch "Easiest way to pass a username to a class" New topic
Author

Easiest way to pass a username to a class

Keyser Logue
Greenhorn

Joined: Mar 08, 2006
Posts: 8
For example in my file I have:

static final String USERNAME = "root";

and

tableModel = new ResultSetTableModel1( JDBC_DRIVER, DATABASE_URL, USERNAME, PASSWORD, DEFAULT_QUERY );

and in another class I have

public ResultSetTableModel1( String driver, String url,
String username, String password, String query )
throws SQLException, ClassNotFoundException
{
// load database driver class
Class.forName( driver );

// connect to database
connection = DriverManager.getConnection( url, username, password );



this all works fine, but obviously I am typing into the class all the url's, usernames etc.....is there a way that it can take that information from a textfield first?
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Yes.

Before you get much further though I would suggest reading up on something called MVC.

http://java.sun.com/blueprints/patterns/MVC.html
Keyser Logue
Greenhorn

Joined: Mar 08, 2006
Posts: 8
thankyou for the quick reply, but a lot of that seems to be html specific. This is just to copy text from a textfield and return it into another class.

A perfect example would be a java gui asking for a password, and using that to access the database
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Yes okay. Well do a search for MVC design and see what you get. You are mixing database code and GUI code and that's not such a good idea.

The basic design pattern applies not only to a web application but any kind of GUI.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Easiest way to pass a username to a class