java.sql.SQLSyntaxErrorException: ORA-00903: 无效 table 名称
java.sql.SQLSyntaxErrorException: ORA-00903: invalid table name
我在 java 应用程序的下拉列表中有所有 table 个名字。
我想在 JLabel 上的 table 中显示记录数。
但我收到以下错误
java.sql.SQLSyntaxErrorException: ORA-00903: invalid table name
我试过这个:
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);
您将字符串作为 table 名称传递。 Table Oracle 中的名称可以在 `` qoutes 内或不带任何引号。
pst = (OraclePreparedStatement) con.prepareStatement("select count(*) as num from " + tableName );
或
pst = (OraclePreparedStatement) con.prepareStatement("select count(*) as num from `" + tableName + "`");
我在 java 应用程序的下拉列表中有所有 table 个名字。 我想在 JLabel 上的 table 中显示记录数。 但我收到以下错误
java.sql.SQLSyntaxErrorException: ORA-00903: invalid table name
我试过这个:
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);
您将字符串作为 table 名称传递。 Table Oracle 中的名称可以在 `` qoutes 内或不带任何引号。
pst = (OraclePreparedStatement) con.prepareStatement("select count(*) as num from " + tableName );
或
pst = (OraclePreparedStatement) con.prepareStatement("select count(*) as num from `" + tableName + "`");