trying to update an Access Database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dav3
    New Member
    • Nov 2006
    • 94

    #1

    trying to update an Access Database

    HI again folks. I spent my weekend coding a function to do statistical analysis on a time series and to my amazement it works without a hitch. I even verified my results were correct with excel. I am having an issue passing these values to my database table. All JDBC drivers are loaded correctly as I can "hard-code" a String and pass run executeUpdate() and it works. Of course I cannot hard-code my entire project.

    Code:
    //update masterTable 
    		      String sqlRecord ="Update MasterTable set [Slope] = "+beta1+" WHERE Abbreviation = "+company;
    		      try
    		      {
    		    	  db_statement.executeUpdate(sqlRecord);
    		    	  System.out.println ("-= record updated =-");
    		      }catch (Exception excep) {
    			      System.out.println ("Unable to update record: n" + excep);
    			      System.exit(0);
    			   }
    The error I am getting is:
    "Unable to update record: njava.sql.SQLEx ception: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1."


    Thoughts, advice, suggestions??

    As I stated earlier if i do something like:
    Code:
    String sqlRecord("Update Mastertable set [slope] = '-0.3234234243645' WHERE Abbreviation = 'AAPL'");
    it works.
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by dav3
    HI again folks. I spent my weekend coding a function to do statistical analysis on a time series and to my amazement it works without a hitch. I even verified my results were correct with excel. I am having an issue passing these values to my database table. All JDBC drivers are loaded correctly as I can "hard-code" a String and pass run executeUpdate() and it works. Of course I cannot hard-code my entire project.

    Code:
    //update masterTable 
    		      String sqlRecord ="Update MasterTable set [Slope] = "+beta1+" WHERE Abbreviation = "+company;
    		      try
    		      {
    		    	  db_statement.executeUpdate(sqlRecord);
    		    	  System.out.println ("-= record updated =-");
    		      }catch (Exception excep) {
    			      System.out.println ("Unable to update record: n" + excep);
    			      System.exit(0);
    			   }
    The error I am getting is:
    "Unable to update record: njava.sql.SQLEx ception: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1."


    Thoughts, advice, suggestions??

    As I stated earlier if i do something like:
    Code:
    String sqlRecord("Update Mastertable set [slope] = '-0.3234234243645' WHERE Abbreviation = 'AAPL'");
    it works.

    You already solved it buddy :-)
    Anyway change this.....

    [code=java]
    String sqlRecord ="Update MasterTable set [Slope] = "+beta1+" WHERE Abbreviation = "+company;
    //you had this
    String sqlRecord ="Update MasterTable set [Slope] = '"+beta1+"' WHERE Abbreviation = "+company;
    //the change is "+beta1+" to '"+beta1+"'
    [/code]

    Enjoy the code.

    Debasis Jana

    Comment

    • dav3
      New Member
      • Nov 2006
      • 94

      #3
      Originally posted by dmjpro
      You already solved it buddy :-)
      Anyway change this.....

      [code=java]
      String sqlRecord ="Update MasterTable set [Slope] = "+beta1+" WHERE Abbreviation = "+company;
      //you had this
      String sqlRecord ="Update MasterTable set [Slope] = '"+beta1+"' WHERE Abbreviation = "+company;
      //the change is "+beta1+" to '"+beta1+"'
      [/code]

      Enjoy the code.

      Debasis Jana

      Gives me the same error, this is driving me nuts. I have looked at it and changed it around in every logical sense I can think of and still get the same error. I have even double checked my ACcess database to make sure there is room for a number of that size, etc...

      Comment

      • madhoriya22
        Contributor
        • Jul 2007
        • 251

        #4
        Originally posted by dav3
        Gives me the same error, this is driving me nuts. I have looked at it and changed it around in every logical sense I can think of and still get the same error. I have even double checked my ACcess database to make sure there is room for a number of that size, etc...
        Hi,
        Try to print you query ... and see what values of beta and company are replacing in your query.

        Comment

        • dmjpro
          Top Contributor
          • Jan 2007
          • 2476

          #5
          Originally posted by dmjpro
          You already solved it buddy :-)
          Anyway change this.....

          [code=java]
          String sqlRecord ="Update MasterTable set [Slope] = "+beta1+" WHERE Abbreviation = "+company;
          //you had this
          String sqlRecord ="Update MasterTable set [Slope] = '"+beta1+"' WHERE Abbreviation = "+company;
          //the change is "+beta1+" to '"+beta1+"'
          [/code]

          Enjoy the code.

          Debasis Jana
          Sorry those two fields are Text.
          So you need to do one more change here.

          [code=java]
          String sqlRecord ="Update MasterTable set [Slope] = '"+beta1+"' WHERE Abbreviation = '"+company+" '";
          [/code]

          Now have a try with this :-)
          Good Luck !

          Debasis Jana

          Comment

          • dav3
            New Member
            • Nov 2006
            • 94

            #6
            ah that worked, thank you kindly again:)


            Now I need to figure out why it updated my first company, but not the second one. Ran through the for loop fine, said it updated but when i checked Access only 1 of the 2 companies was updated.


            EDIT: seem to have figured it out, just called a closeconnection function and it worked:)

            Comment

            • dmjpro
              Top Contributor
              • Jan 2007
              • 2476

              #7
              Originally posted by dav3
              ah that worked, thank you kindly again:)


              Now I need to figure out why it updated my first company, but not the second one. Ran through the for loop fine, said it updated but when i checked Access only 1 of the 2 companies was updated.


              EDIT: seem to have figured it out, just called a closeconnection function and it worked:)
              I already told you that you solved it but you can't do that in Java Coding.
              [code=java]
              String sqlRecord("Upda te Mastertable set [slope] = '-0.3234234243645 ' WHERE Abbreviation = 'AAPL'");
              [/code]

              If your table fields are text then you need to have semi-colons.

              Debasis Jana

              Comment

              Working...