1

So I'm trying to create an unspecified table name with an unspecified columns, however, I'm new to prepareStatement and I'm not exactly sure what to do. This is how I'm thinking about it I know I'll need a loop for multiple entries of "line" which is the table name but how can I deal with the columns? I think I'm specifying the number of columns in here (4). How can I do this without specifying? and what should I put for setString if the value will differ based on the table name? I'm kind of confused and I was hoping that someone will explain this to me

loop start ....
line = kb.next();
sql = "Create TABLE " + line  + "(?,?,?,?)";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,?);
pstmt.executeUpdate();
loop end
rullzing
  • 622
  • 2
  • 10
  • 22
  • 4
    Prepared statement placeholders can only be used in places where SQL allows expressions. Column names in a `CREATE TABLE` statement are not expressions. You need to use string concatenation for this. – Barmar Oct 30 '15 at 23:32
  • 1
    also, mysql is not fond of `create table 1 (id int);` but will accept that tablename wrapped in back-ticks – Drew Oct 30 '15 at 23:34
  • 2
    Don't use a prepared statement. It's the wrong approach. – Bohemian Oct 30 '15 at 23:40

1 Answers1

0

It's unlikely that you'll be able to get this to work on any database.

For Oracle-specific reasoning, see Why cannot I use bind variables in DDL?

Community
  • 1
  • 1
Ken Geis
  • 904
  • 6
  • 17