wood burning stoves*
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
Author

problems with getting text from field...

Keyser Logue
Greenhorn

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
this:


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 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: 94
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: problems with getting text from field...
 
Similar Threads
Database connectivity in struts 2
Help - - - ClassNotFoundException: com.mysql.jdbc.Driver
simple Sql connectivity problem
Easiest way to pass a username to a class
Help with this code!