JDBC Mini Swing App
1 posts in topic
Flat View  Flat View

Posted By:   Aaron_Tahir
Posted On:   Wednesday, March 23, 2005 12:31 AM

Hi everyone.Im new to this forum.i created a simple jdbc swing program.I have 4 textfields, how can i get the values of the textfields and insert it to the database.I use access and I can retrieve resultsets but i cant insert thru textfields.pls help thanks...

Re: JDBC Mini Swing App

Posted By:   David_Thornton  
Posted On:   Wednesday, March 23, 2005 02:03 PM

Very simplisticly you need to code something along these lines;

try {
Connection con = DriverManager.getConnection([url for database goes here]);
PreparedStatement pstmt = con.prepareStatement("INSERT INTO MyTable VALUES( ?, ?, ?, ? )");
pstmt.setString(1, textField1.getText());
pstmt.setString(2, textField2.getText());
pstmt.setString(3, textField3.getText());
pstmt.setString(4, textField4.getText());
catch (Exception e) {

You will get errors if the length of any of the strings returned by JTextField.getText() is longer than the corresponding column length so while the above will work it is a very simplistic solution.
About | Sitemap | Contact