Solved

SQL Insert Into

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
TreeSet comparator example 7 99
grep code 4 200
spring JDBC Template example error 26 293
null output 3 36
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Riverbed Technology's webinar discusses networking for the cloud era with simplified SD-WAN cloud connectivity.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 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