• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problems with getting text from field...

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic