使用准备好的语句设置表名我试图使用准备好的语句来设置一个表名以从中选择数据,但是在执行查询时,我一直会收到一个错误。错误和示例代码显示在下面。[Microsoft][ODBC Microsoft Access Driver] Parameter 'Pa_RaM000' specified where a table name is required.private
String query1 = "SELECT plantID, edrman, plant, vaxnode FROM [?]"; //?=datepublic Execute(String reportDate){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(Display.DB_MERC);
PreparedStatement st = conn.prepareStatement(query1);
st.setString(1, reportDate);
ResultSet rs = st.executeQuery();对造成这一切的原因有什么想法吗?
3 回答
临摹微笑
TA贡献1982条经验 获得超2个赞
private String query1 = "SELECT plantID, edrman, plant, vaxnode FROM [" + reportDate + "?]";
FFIVE
TA贡献1797条经验 获得超6个赞
String sql = "IF ? = 99\n";sql += "SELECT * FROM first_table\n"; sql += "ELSE\n";sql += "SELECT * FROM second_table"; PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1, 99);
添加回答
举报
0/150
提交
取消