要创建一个表PrepapredStatement
这是不可能的,因为当你做
q= "create table ? (emp_id number (10), emp_name varchar (15))";
因此,在现实中,它会执行这个查询这里:
create table 'table_name' (emp_id number (10), emp_name varchar (15))
和'table_name'
在您创建表格时被禁止,因此建议您使用PrepapredStatement
这样玩:
当您准备报表,你会得到前面的查询就可以得到像这样
preparedStatement.toString()
这样你就可以改变的开始,并与
""
到底
''
因为
"
被允许在甲骨文
try {
Class.forName(driver);
Connection connection = DriverManager.getConnection(DB_URL, DB_username, DB_password);
PreparedStatement preparedStatement = connection.prepareStatement("create table ? (emp_id number (10), emp_name varchar (15))");
preparedStatement.setString(1, "table_name");
System.out.println(preparedStatement.toString());
Statement st = connection.createStatement();
int i = st.executeUpdate(preparedStatement.toString().replaceAll("\"", "\""));
JOptionPane.showMessageDialog(new JDialog(), "Table is Created");
} catch (ClassNotFoundException | SQLException e) {
JOptionPane.showMessageDialog(new JDialog(), "Table is not Created");
}
的想法很简单create a table with a name which contain spaces。
你有没有得到任何错误,你的表格创建了,你的问题到底是什么? –
您无法参数化对象标识符,如表名称 –