Meh*_*had 4 java sql oracle jdbc syntax-error
我在 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);
}
Run Code Online (Sandbox Code Playgroud)
在 Oracle 中,引号 ( 's) 用于表示字符串文字。对象名称(例如表)不应被它们包围。丢失引号,你应该没问题:
pst = (OraclePreparedStatement) con.prepareStatement
("select count(*) as num from " + tableName);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6416 次 |
| 最近记录: |