wood burning stoves 2.0*
The moose likes JDBC and the fly likes Create table error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Create table error" Watch "Create table error" New topic
Author

Create table error

Amar Deep Singh Chaudhary
Ranch Hand

Joined: Dec 26, 2006
Posts: 49
hi rancher's
i am working with ms-Access database.and i am trying to create a table in the database by using the query.but i am geetin a syntax error.please tell me the error.
the code is as follows:
String emp_id=request.getParameter("empid");
/****

String q="create table '"+emp_id+"'('date' varchar2 (20),'status' varchar2 (10))";
int j=st2.executeUpdate(q);


"A thinking mind never dies"
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

Amar,
You are currently running:
create table 'emp_id'('date' varchar2 (20),'status' varchar2 (10))

The first thing I see is that usually the table name is not in quotes. Try running the query directly at the database command line.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Amar Deep Singh Chaudhary
Ranch Hand

Joined: Dec 26, 2006
Posts: 49
dear jaenne
i think you did't read the first line before the coding in which i am taking emp_id as an String from getParameter() method.

i am using the database Ms Access.please help me.your suggestion does't work.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

Amar,
I saw that. The variable explains the double quotes (for Java). The single quotes are only used for SQL and are not needed for a table name.

It should be:
create table "+emp_id+"..
not:
create table '"+emp_id+"'..

What error are you getting when you run the statement at the database command line?
Parthasarathy balakrishnan
Greenhorn

Joined: Apr 20, 2007
Posts: 14
Originally posted by Jeanne Boyarsky:
Amar,
You are currently running:
create table 'emp_id'('date' varchar2 (20),'status' varchar2 (10))

The first thing I see is that usually the table name is not in quotes. Try running the query directly at the database command line.





-------------------------------------------------------------------------
System.out.println("Before The table creation");
String q="create table partha1(date1 varchar(20),place varchar(10))";
int i=st.executeUpdate(q);
System.out.println("Table Updated"+i);


Me partha found two errors in the code

1.in access datatype has to b changed from varchar2(20) to varchar(20)
access supports varchar(20)

2.date is the datatype in database it can'nt b used as column name
so change the date as date1


Thanks and Regards,<br />-------------------<br />Parthasarathy Balakrishnan,<br />Bangalore.
 
Don't get me started about those stupid light bulbs.
 
subject: Create table error
 
Similar Threads
Oracle Cursor
date mapping problem in Hibernet
not able to use identity attribute in oracle
problem in inserting data
unable to use identity columns