1

为什么下面的代码会出现“参数索引超出范围(1> 参数数量,即 0)”?

private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {                                          
   String tabId = lblTableId.getText().trim();
   try { 
        DBConnection db = new DBConnection();
        Connection con = db.getConnectionMyWareHouse(Main.dwh.lblSessionWarehouse.getText());
        String query1 = "Select DWTableId,DWTableName from datawarehousetable where DWTableId=? and DWTableName=? ";
        System.out.println("OG Query ---->"+query1);
        PreparedStatement ps1 = con.prepareStatement(query1);
        ps1.setString(1, tabId);
        ResultSet rs1 = ps1.executeQuery();
        String strTN = "";
        if(rs1.next())
        {
            strTN = rs1.getString("DWTableName");
        }

        String query2 = "Delete from datawarehousetable where DWTableId= ?";
        System.out.println("OG Query ---->"+query2);
        PreparedStatement ps2 = con.prepareStatement(query2);
        ps2.setString(1, tabId);
        int rs2 = ps2.executeUpdate();

        String query3 = "Drop table " + strTN;
        System.out.println("OG Query ---->"+query3);
        PreparedStatement ps3 = con.prepareStatement(query3);
        ps3.setString(1, tabId);
        int rs3 = ps3.executeUpdate();

        JOptionPane.showMessageDialog(null, "Table deleted successfully.", "Successful", JOptionPane.INFORMATION_MESSAGE);
        con.close();
    }
    catch(Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(null, "Error : " + e.getMessage(),"Error", JOptionPane.ERROR_MESSAGE);
    }    
}                                         
4

0 回答 0