Solved

SQL Insert Into

Posted on 2004-10-06
3
1,311 Views
Last Modified: 2008-02-01
Dear Friends,

I am using MS Access XP , JavaWebServer 2.0 running on Windows XP Service Pack 2.0. I have a table named Conduction1 which consist several columns and I want to dynamically add records to it. I can read from table and write to it but whenever I try to add a record it throws exception. I have created a class named DBC and a procedure in it to run SQL statements named as runSQL.

Following is the code of runSQL.

public void runSQL(String command)
  {
    try{
     stmt.executeUpdate(command);
    }catch(SQLException e){System.out.println("SQL Exception occured in the RunSQL");}
  }

And I am using this piece of code in JSP page

                String SQLQuery="INSERT INTO "+TableName+" (NUMBER) "+" VALUES ('"+username+"')";
            out.println("Query is="+SQLQuery);  //this is to see if there is a problem with query statement
            dbc.runSQL(SQLQuery);

I will appreciate any help and comments

Thanks in advance
0
Comment
Question by:MacroLand
3 Comments
 
LVL 11

Accepted Solution

by:
sompol_kiatkamolchai earned 100 total points
ID: 12245521
I think (NUMBER) is a reserved word. Try to change the name of this column.

If problem still persist, please post the thrown exception.
0
 

Assisted Solution

by:ae1974
ae1974 earned 25 total points
ID: 12248501
You have an issue with  the syntax that you are trying to use.

I sugget that you do the following:

1. Write an SQL Statement in Access and test it works.
2. Copy this SQL Statement into your Java program and then check that it works
3. Make the statement dynamic in Java.

For example:  

try this in Access "INSERT INTO TestTable (Field1, Field2) VALUE (123, 345)"

Then change your code to:
String SQLQuery="INSERT INTO TestTable (Field1, Field2) VALUE (123, 345)";

Then if this works... change your code to something like:

String SQLQuery = "INSERT INTO " + tablename + "(" + fields + ") VALUE ("+values+")";

I hope this helps.
0
 
LVL 4

Author Comment

by:MacroLand
ID: 12251216
I want to thank both sompol_keatkamolchai and ae1974. The problem arised from the column of the name that is NUMBER.

Thanks for your help
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How do we balance the user experience (UX) with reasonable security measures? It can be done, if you keep these fundamentals in mind.
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question