Results 1 to 5 of 5
  1. #1
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default 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
    Java 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' ");
    	}
    }
    dbConnection.java
    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

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default 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?

  3. #3
    RichersooN is offline Senior Member
    Join Date
    Jan 2011
    Location
    Rizal Province, Philippiines
    Posts
    167
    Rep Power
    0

    Default 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

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default 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?

  5. #5
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default Re: Hi why is it my database never update/edit its data

    Try
    Java Code:
    protected static final String dbSearchUrl = "jdbc:Odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" +dataSourceName;
    Try to check (in program) if the database exist on the path.

Similar Threads

  1. create,edit ,delete in JSP usin struts and SQL server as database in jdeveloper
    By gurpreet.singh in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-11-2011, 12:43 PM
  2. Delete and edit data in xml file using JSP
    By gurpreet.singh in forum JavaServer Pages (JSP) and JSTL
    Replies: 6
    Last Post: 03-10-2011, 08:07 AM
  3. Update a price in a database
    By sandraW in forum New To Java
    Replies: 14
    Last Post: 08-29-2010, 04:41 AM
  4. edit data??
    By Daniela_v in forum New To Java
    Replies: 4
    Last Post: 03-06-2009, 03:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •