wood burning stoves 2.0*
The moose likes JDBC and the fly likes Get data from TextField ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Get data from TextField ?" Watch "Get data from TextField ?" New topic
Author

Get data from TextField ?

Ivor Horton Evil
Greenhorn

Joined: Oct 30, 2002
Posts: 6
Hello buddies,
I am designing a simple data based software in GUI.
The user will give input in the textfields , and after pressing the "submit" button, it will take tht data from the textfield to the data base.

For Eg: Name : Ivor Horton (JTextField1)
Phone: 12345 (JTextField2)
State: Nevada (JTextField3)
(Table name is INFO and colums are Name, Phone and State)
kindly send me a sample code or some guidelines to do this .... i know its very easy stuff for u guys out there
Pedro Garcia
Greenhorn

Joined: Sep 12, 2002
Posts: 15
You must use getText() method..
JTextField1.getText();
And for the database access
the you must to make the connection to the database. Its depend your jdbc driver and database that you use..


Pedro
Ivor Horton Evil
Greenhorn

Joined: Oct 30, 2002
Posts: 6
Hi ther Pedro,
Thanks.. but that i know how to get text from the text field.. I wanna know how to write that data into the database ..
like for fetching data from the database we use this method of the "recordset" .
Eg: (where "rs" is the object of recordset)
rs.getString (columnName);
So how we are going to write the data that the user typed in the JTextField1.
Eg: String str=null;
str= JTextField1.getText();
Now how Am i going to write that String which 'str' is holding ... I think there is a method
rs.updateString (columnName, str);
But I am not sure . Can u now tell me in detail wht to do ?
Jeff Grant
Ranch Hand

Joined: Dec 19, 2001
Posts: 169
You'd need to know how to write SQL to do that.
Here's a simple example...
String insertString = "insert into table_name values(" + jTextField1.getText() + ")";
Then you'd simply submit that to the database. However, you have not even established a connection to the DB yet so that cannot be done. It looks like you want others to do the work for you.
I'd suggest that you do a little research at java.sun.com about how to connect to the database.
Then, if you still cannot get your field to insert after your connection is made, go to www.oracle.com to see how to write SQL queries / inserts.
Then, if you STILL cannot get your field to insert into the table, post on back here and ask a more specific question with examples of your working code. Ask step by step, don't just say "I have a text field, how do I insert that into the database?" IMO, it's really annoying, we all had to do work ourselves at some point. And just search javaranch and you'll find most of the information you're looking for anyways.
Ivor Horton Evil
Greenhorn

Joined: Oct 30, 2002
Posts: 6
hi ther Jeff.
Dude thanks alot, U just solved my problem. Actually you mis-judged me. I am a great programmer but sometimes even the lion needs help to get out of the mud trap dont worry about the SQL statments, i can even introduce a new version of my own SQL lol Actually i was thinking that there will be a Java method to write the data from the textfield, but you corrected me, now i got the hint to execute an SQL query from the program.. Thanks alot dude.
I will post a problem if i might get stuck somewher.
Paul Misoni
Greenhorn

Joined: Jan 02, 2001
Posts: 16
Helpful reminder: You may actually want to check first to see if the record already exists in the database before trying to do and insert.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get data from TextField ?