my dog learned polymorphism
The moose likes Beginning Java and the fly likes problems with getting text from field... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problems with getting text from field..." Watch "problems with getting text from field..." New topic

problems with getting text from field...

Keyser Logue

Joined: Mar 08, 2006
Posts: 8
Basically I want to pass some text from a field to be used as a log in.

Basically in my classes I have

static final String USERNAME = "root";


tableModel = new ResultSetTableModel1( JDBC_DRIVER, DATABASE_URL, USERNAME,

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 there a simple way that it can take that information from a textfield first?

That way I dont need String USERNAME = "root"; as the only way of logging on as someone OTHER than root is to change the code, which is not what I want
Tom Fulton
Ranch Hand

Joined: Mar 30, 2006
Posts: 96
If the field is on a GUI, you can just call component.getText(), where component is a TextField reference (actually, any TextComponent, including TextFields and TextAreas).

If the field is on an HTML or JSP form, you need to get the value from the field name. For example, in a servlet, if the field name is "loginName", you would get it this way:

String login = request.getParameter("loginName");
Of course, there is much more to an application, standalone or enterprise...the rest of the infrastructure would depend on what you are doing.
I agree. Here's the link:
subject: problems with getting text from field...
jQuery in Action, 3rd edition