| | |
Inserting Data into Access Database
![]() |
•
•
Join Date: Jun 2006
Posts: 1
Reputation:
Solved Threads: 0
Hello I need help I have created a application that pulls data from and is supposed to update and insert data into an access database. I have been successful in pulling data from it using first, last, previous and next buttons.
However, I can't get my insert button to work. Here is the code I have for that button. I can't figure out what is wrong in the code. Can some one please help?
This is the connection code.
This is the code for the insert button:
I get no errors at compilation. Everything else works, but nothing is inserted and it goes right to the catch and the event handler message comes up.
However, I can't get my insert button to work. Here is the code I have for that button. I can't figure out what is wrong in the code. Can some one please help?
This is the connection code.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection("jdbc:odbc:Miller");
stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
sqlQuery = "select Cust_ID, Name, Phone, Class_Level, Course_ID, Status, Pay_Terms from customers";
rs = stmt.executeQuery(sqlQuery);This is the code for the insert button:
class insertButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try
{
if (inserting == false) { // clear text boxes
numF.setText("");
custF.setText("");
phneF.setText("");
levelF.setText("");
courseF.setText("");
statF.setText("");
termsF.setText("");
insertButton.setText("Save");
inserting = true;
}
else
{ // finalize the insert
rs.moveToInsertRow();
int custNo = Integer.parseInt(numF.getText());
rs.updateInt(1, custNo);
rs.updateString(2, custF.getText());
rs.updateString(3, phneF.getText());
rs.updateString(4, levelF.getText());
rs.updateString(5, courseF.getText());
rs.updateString(6, statF.getText());
rs.updateString(7, termsF.getText());
rs.insertRow();
insertButton.setText("Insert");
inserting = false;
}
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(null, "Nothing inserted",
"Event Handler Message",
JOptionPane.INFORMATION_MESSAGE);
}
}
}
I get no errors at compilation. Everything else works, but nothing is inserted and it goes right to the catch and the event handler message comes up.
•
•
Join Date: Jun 2006
Posts: 2
Reputation:
Solved Threads: 0
Hi, near as I can tell this looks ok.
Some things to look at
* Is rs always properly initialized in the "else" code?
* Is there another "rs" variable declared in another scope?
* Is this a legal row -- are all the required columns set? Are all the fields in legal format (matching the DDL) ?
any more information you can provide?
Jason
Sunflower Network - Instant Computer Help
www.sunflowernetwork.com
Some things to look at
* Is rs always properly initialized in the "else" code?
* Is there another "rs" variable declared in another scope?
* Is this a legal row -- are all the required columns set? Are all the fields in legal format (matching the DDL) ?
any more information you can provide?
Jason
Sunflower Network - Instant Computer Help
www.sunflowernetwork.com
![]() |
Similar Threads
- Writing to an Access Database (Visual Basic 4 / 5 / 6)
- load data from access database into form (VB.NET)
- Understanding inserting data into an Access table using VB.NET (VB.NET)
- Updating a record in an MS Access database file using DataSets (VB.NET)
- Read data from Access Database through PHP (PHP)
- Create an Access Database using Java (Java)
- JDBC for Access Database (Java)
- Writing to an Access Database using Java... (Java)
Other Threads in the Java Forum
- Previous Thread: Java equivalant to C's getchar()
- Next Thread: connecting to mysql in linux
| Thread Tools | Search this Thread |
-xlint add android api applet application applications array arrays automation bank bi binary blackberry bluetooth chat class clear client code compile compiler component database development digit eclipse equation error event formatingtextintooltipjava fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image infinite int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list main map method methods mobile myregfun netbeans nonstatic notdisplaying openjavafx pearl problem program project qt recursion repositories scanner screen scrollbar server set sms sort sorting spamblocker sql sqlserver state storm string superclass swing system thread threads tree variablebinding windows xor





