Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL and variables with Java and MS Access

Status
Not open for further replies.

mcklsn

Programmer
Mar 16, 2003
40
US
I know this is a very basic question, but I can't find an understandable answer for it.
I want to create an SQL insert command in Java to send to an MS Acess database. I want to send values that have been computed and so they don't exist as strings. I need to know the syntax I need to use with a variable when I'm putting the insert request together so I can send it to my MS Access database. I have all the code working to query the database, but this is the first time I've tried putting something into it from my program.
I've received great help from Tek-Tips in the past. I hope someone will be kind enough to answer this very basic question for me.Thanks.
 
1. ... INSERT command to Access....
Code:
  INSERT INTO [tablename] VALUES ('etc',3,'that last one was a number',#3/3/2003#,'last one was a date')

  INSERT INTO [tablename] (SELECT * FROM [othertable])
There are other variants, but that should get you started. Note you can specify which fields to "insert into" by adding a fieldlist after the table name, i.e. "INTO [tablename] ([DT_FROM],[SOME_TEXT],[An Awful Access #FieldName#])


2. ....Java ... and so they don't exist as strings. ...

Use the toString() function. If they are int's or long's or double's, etc, use the related Java Classes, i.e. Integer class.


3. Good luck on your assignment
 
foolio12,
Thanks for the help. It's nice to know that somebody didn't think it was too simple a question to bother with.
Here's another on those extremely simple questions that has me stumped. I have to define some extremely long strings, some over 300 characters long. These are very hard to work with and obviously are not visible all at one time in the editor. Is there a line continuation character that can be used in the middle of a string definition without breaking the string into illegal pieces, so that I can define a single string on multiple lines to make it manageable and readable? It seems that there should be one, but everything that I have tried has failed.
Help!
Thanks again
mcklsn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top