create any table name with prepareStatement jdbc java

时间:2015-10-30 23:23:43

标签: java mysql sql jdbc prepared-statement

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

1 个答案:

答案 0 :(得分: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?