Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Insert Into

Posted on 2004-10-06
3
Medium Priority
?
1,332 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Accepted Solution

by:
sompol_kiatkamolchai earned 400 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 100 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Want to know how to use Exchange Server Eseutil command? Go through this article as it gives you the know-how.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

670 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