473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

trying to update an Access Database

94
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.

Expand|Select|Wrap|Line Numbers
  1. //update masterTable 
  2.               String sqlRecord ="Update MasterTable set [Slope] = "+beta1+" WHERE Abbreviation = "+company;
  3.               try
  4.               {
  5.                   db_statement.executeUpdate(sqlRecord);
  6.                   System.out.println ("-= record updated =-");
  7.               }catch (Exception excep) {
  8.                   System.out.println ("Unable to update record: n" + excep);
  9.                   System.exit(0);
  10.                }
  11.  
The error I am getting is:
"Unable to update record: njava.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1."


Thoughts, advice, suggestions??

As I stated earlier if i do something like:
Expand|Select|Wrap|Line Numbers
  1. String sqlRecord("Update Mastertable set [slope] = '-0.3234234243645' WHERE Abbreviation = 'AAPL'");
  2.  
it works.
Oct 9 '07 #1
6 1883
dmjpro
2,476 2GB
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.

Expand|Select|Wrap|Line Numbers
  1. //update masterTable 
  2.               String sqlRecord ="Update MasterTable set [Slope] = "+beta1+" WHERE Abbreviation = "+company;
  3.               try
  4.               {
  5.                   db_statement.executeUpdate(sqlRecord);
  6.                   System.out.println ("-= record updated =-");
  7.               }catch (Exception excep) {
  8.                   System.out.println ("Unable to update record: n" + excep);
  9.                   System.exit(0);
  10.                }
  11.  
The error I am getting is:
"Unable to update record: njava.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1."


Thoughts, advice, suggestions??

As I stated earlier if i do something like:
Expand|Select|Wrap|Line Numbers
  1. String sqlRecord("Update Mastertable set [slope] = '-0.3234234243645' WHERE Abbreviation = 'AAPL'");
  2.  
it works.

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

Expand|Select|Wrap|Line Numbers
  1. String sqlRecord ="Update MasterTable set [Slope] = "+beta1+" WHERE Abbreviation = "+company;
  2. //you had this
  3. String sqlRecord ="Update MasterTable set [Slope] = '"+beta1+"' WHERE Abbreviation = "+company;
  4. //the change is "+beta1+" to '"+beta1+"'
  5.  
Enjoy the code.

Debasis Jana
Oct 9 '07 #2
dav3
94
You already solved it buddy :-)
Anyway change this.....

Expand|Select|Wrap|Line Numbers
  1. String sqlRecord ="Update MasterTable set [Slope] = "+beta1+" WHERE Abbreviation = "+company;
  2. //you had this
  3. String sqlRecord ="Update MasterTable set [Slope] = '"+beta1+"' WHERE Abbreviation = "+company;
  4. //the change is "+beta1+" to '"+beta1+"'
  5.  
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...
Oct 9 '07 #3
madhoriya22
252 100+
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.
Oct 9 '07 #4
dmjpro
2,476 2GB
You already solved it buddy :-)
Anyway change this.....

Expand|Select|Wrap|Line Numbers
  1. String sqlRecord ="Update MasterTable set [Slope] = "+beta1+" WHERE Abbreviation = "+company;
  2. //you had this
  3. String sqlRecord ="Update MasterTable set [Slope] = '"+beta1+"' WHERE Abbreviation = "+company;
  4. //the change is "+beta1+" to '"+beta1+"'
  5.  
Enjoy the code.

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

Expand|Select|Wrap|Line Numbers
  1. String sqlRecord ="Update MasterTable set [Slope] = '"+beta1+"' WHERE Abbreviation = '"+company+"'";
  2.  
Now have a try with this :-)
Good Luck !

Debasis Jana
Oct 9 '07 #5
dav3
94
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:)
Oct 9 '07 #6
dmjpro
2,476 2GB
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.
Expand|Select|Wrap|Line Numbers
  1. String sqlRecord("Update Mastertable set [slope] = '-0.3234234243645' WHERE Abbreviation = 'AAPL'");
  2.  
If your table fields are text then you need to have semi-colons.

Debasis Jana
Oct 9 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: jimserac | last post by:
I had previously posted this in an Access forum with negative results so will try here. Although this question specifies an Access database, I also wish to accomplish this with a large MS SQL...
2
by: Niyazi | last post by:
Hi, I have not understand the problem. Before all the coding with few application everything worked perfectly. Now I am developing Cheque Writing application and when the cheque is clear the...
1
by: Michael Eisner | last post by:
I have an MS Access 8.0 (Office97) program that has a form called FO-008 that I need to replace on several users computers in different locations without me being there doing it manually. I'm...
5
by: PAUL | last post by:
Hello, I have 2 tables with a relationship set up in the dataset with vb ..net. I add a new record to the parent table then edit an existing child record to have the new parent ID. However when I...
7
by: lmnorms1 | last post by:
Hello, I am trying to update an access database record date field that matches a specific date. The code is not working. Anyone have any advice? Here is the code: Dim gConnString As String =...
2
by: Stephen D Cook | last post by:
I am trying to write to an ACCESS database. I have full permission and Read/Write capability set for the database and folder. But when I get to MoveLast or Update, I get an error of the database is...
5
by: Yew12 | last post by:
I have been trying to update the details in a access database but, all I get is a white screen and all the errors I have built-in give me no help at all. All help is greatly appreciated. ...
3
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID...
25
by: pereges | last post by:
Hello, I'm trying to build a database driven website for a library management system. The database is stored on a remote server which all of my team mates can access. I've installed MySQL, PHP and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.