Solved

SQL Insert Into

Posted on 2004-10-06
3
1,306 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
JSP call a method on a session attribute which is an object 2 61
logging jar 1 106
console vs log file 16 77
Looking for some programs to resell or buy source codes 1 75
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
With the rapid rise in mobile usage, mobile devices are here to stay and have become an integral part of doing business. Here are 9 great apps for your BYOD environment.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now