[英]java.sql.SQLSyntaxErrorException: ORA-00903: invalid table name
我在java应用程序的下拉列表中有所有表名。 我想在JLabel上显示表中的记录数。 但我收到以下错误
java.sql.SQLSyntaxErrorException:ORA-00903:表名无效
我试过这个:
try {
String tableName = LoginFrame.userName + "." + this.ddlTableName.getSelectedItem().toString();
JOptionPane.showMessageDialog(null, tableName);
pst = (OraclePreparedStatement) con.prepareStatement("select count(*) as num from '" + tableName + "'");
rs = pst.executeQuery();
while (rs.next()) {
this.lblRecordStat.setText(rs.getString("num"));
}
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex);
System.out.println(ex);
}
在Oracle中,引号( '
s)用于表示字符串文字。 对象名称(例如表)不应该被它们包围。 丢失报价,你应该没问题:
pst = (OraclePreparedStatement) con.prepareStatement
("select count(*) as num from " + tableName);
您将字符串作为表名传递。 Oracle中的表名可以在``qoutes里面,也可以没有任何引号。
pst = (OraclePreparedStatement) con.prepareStatement("select count(*) as num from " + tableName );
要么
pst = (OraclePreparedStatement) con.prepareStatement("select count(*) as num from `" + tableName + "`");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.