Solved

SQL Insert Into

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
simple jsp servlet and webservice web example 5 110
Javascript onclick event 4 101
java beans and EJBs 5 182
dateFashion java challenge 9 128
This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

12 Experts available now in Live!

Get 1:1 Help Now