Results 1 to 5 of 5
- 09-29-2011, 03:06 AM #1
Senior Member
- Join Date
- Jan 2011
- Location
- Rizal Province, Philippiines
- Posts
- 167
- Rep Power
- 0
Hi why is it my database never update/edit its data
I created a program that will update a database, ms access via odbc, supposedly it will update data in the database, there's no error but the database didn't update:
dbEdit.java
dbConnection.javaJava Code:public class dbEdit extends dbConnection{ PreparedStatement statement=null; public dbEdit (){ super(); } public void saveToDb(String mySql){ try{ statement = con.prepareStatement(mySql); statement.executeUpdate(); }catch(SQLException sqlex){ sqlex.printStackTrace(); } } public static void main(String[]args){ dbExaminee f = new dbExaminee(); f.saveToDb("update examineeplanttb set remark='FAILED' "); } }
Java Code:public class dbConnection { public dbConnection(){ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con = DriverManager.getConnection(dbSearchUrl,dbSearchUser,dbSearchPassword); }catch(ClassNotFoundException cnfex){ JOptionPane.showMessageDialog(null, "Failed to load JDBC/ODBC driver."); cnfex.printStackTrace(); System.exit(1); //terminate program }catch(SQLException sqlex){ JOptionPane.showMessageDialog(null, "Failed to load JDBC/ODBC driver."); sqlex.printStackTrace(); System.exit(1); //terminate program } } protected Connection con; protected static final String dataSourceName = "psalmDSN"; protected static final String dbSearchUrl = "jdbc:odbc:" +dataSourceName; protected static final String dbSearchUser = ""; protected static final String dbSearchPassword = ""; }
Please tell me whats wrong with my code
- 09-29-2011, 09:23 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Hi why is it my database never update/edit its data
Does MS-Access require a commit() call?
I do notice you never close your resources (statement or connection), but that won't be anything to do with it.
If the commit isn't the reason, then does that update statement work directly in Access?
- 09-30-2011, 12:44 AM #3
Senior Member
- Join Date
- Jan 2011
- Location
- Rizal Province, Philippiines
- Posts
- 167
- Rep Power
- 0
Re: Hi why is it my database never update/edit its data
Closing of connection and statement will not be an issue, either commit is not an issue, thats not only update the current data in the database.
Help please
- 09-30-2011, 09:57 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Re: Hi why is it my database never update/edit its data
You still need to close your resources...that's basic JDBC.
If it's not a commit issue then either you are not using the same database, you are not checking the update correctly, or there is nothing to update.
None of which we can help you with since we cannot see your database.
How are you confirming whether the update has worked?
- 10-01-2011, 04:13 AM #5
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Similar Threads
-
create,edit ,delete in JSP usin struts and SQL server as database in jdeveloper
By gurpreet.singh in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 03-11-2011, 12:43 PM -
Delete and edit data in xml file using JSP
By gurpreet.singh in forum JavaServer Pages (JSP) and JSTLReplies: 6Last Post: 03-10-2011, 08:07 AM -
Update a price in a database
By sandraW in forum New To JavaReplies: 14Last Post: 08-29-2010, 04:41 AM -
edit data??
By Daniela_v in forum New To JavaReplies: 4Last Post: 03-06-2009, 03:12 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks