Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding column to the table in sql using preprepareStatement.

 
Ashwani Singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to add a new new column in already existing table named "Forumtable".I want to give the name of the column dyanamically using setString() method or so.My code is:


ps3=con.prepareStatement("alter table forumtable add (? varchar2(500),? varchar2(20) )");
ps3.setString(1,newans);
ps3.setString(2,newanswerer);
ps3.executeQuery();

here i wish to add two columns to the table.By this code i am getting sqlexception as ORA-00904: : invalid identifier. How to do it?Please help its urgent.
 
Saif Asif
Ranch Hand
Posts: 440
Eclipse IDE Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings Ashwani and welcome to the ranch,

I think you have an error in your SQL. shouldnt it be something like this
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Ashwani! I've moved your question to a better suited forum, the Ranch Office forum is just for discussions about this site.

Saif Asif wrote:I think you have an error in your SQL. shouldnt it be something like this...

No, that was not the problem. The COLUMN keyword needs only be specified when adding just one column, without the brackets. When the columns are put into the brackets, the COLUMN keyword must not be specified.

The problem is that column names cannot be parametrized. You need to specify the column names right in the text of the statement, no question marks there. Only literals (text, date or numeric) can be parametrized. That should fix it.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12127
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Putting in that "this is urgent" doesn't really help around here. First, it isn't our problem. Next, a lot of folks will say "hmmm...this was posted a while ago and it's urgent, so i'm probably too late. I'll go help someone else".

I would strongly suggest you read our FAQ on HowToAskQuestionsOnJavaRanch.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic