Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create table error

 
Amar Deep Singh Chaudhary
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34105
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Amar Deep Singh Chaudhary
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34105
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic