1

I have code which sets an ID value from query :

Connect c=new Connect();
Statement stmt=c.Connstr.createStatement();
ResultSet rs = stmt.executeQuery("select Res_ID,RDate,Receipt,MethodofPayment as 'Installmets?',InstallmentCount as 'Installmets Count',InstallmentStartDate as 'Start',Client_Name as 'Client',Project_Name 'Project',Unit_Name as 'Unit' from reservationwithdetails where Client_ID="+Vars.get_Client_ID()+"");
SearchTable.setModel(buildTableModel(rs));
ResultSet NewRec = stmt.executeQuery(""
    + "select ID from reservation "
    + "where "
    + "Client_ID ="+Vars.get_Client_ID()+" and Project_ID ="+Vars.get_Project_ID()+" and Unit_ID ="+Vars.get_Unit_ID()+"" );
while(NewRec.next()){
    Vars.Set_Newest_Reservation_ID(NewRec.getInt("ID"));
}

So, here I give a value for Vars.Set_Newest_Reservation_ID(int ID)

when I call it, I use Vars.Newest_Reservation_ID(), so I add new wizard jassper report and design the query like this :

SELECT Res_ID, RDate, UnitPrice, ReversationFee, Client_Name, Project_Name, Unit_Name FROM reservationwithdetails
WHERE Res_ID = Vars.Newest_Reservation_ID()

I got an error with this statement form and I know it's wrong ... now how can I make this report query get the Res_ID Value from external variable?

Cache Staheli
  • 3,510
  • 7
  • 32
  • 51
Omar
  • 37
  • 1
  • 10
  • You should use [Parameters](http://jasperreports.sourceforge.net/sample.reference/query/index.html#query) – Alex K Aug 18 '16 at 19:58
  • What is `Vars.Newest_Reservation_ID()`?, from where do you get this, where is it define? (note probably Alex is correct, you can only use parameters in query, but asking since it would be good to clarify question. – Petter Friberg Aug 18 '16 at 20:42
  • ok ... I used the parameters by static value ... and it worked ... but what if i use the Default Value Expression and give it Vars.get_Newest_Reservation_ID() should it work like this to tell the parameter its value ? – Omar Aug 18 '16 at 21:14
  • Vars.Newest_Reservation_ID() take its value from other form by setter : Vars.Set_Newest_Reservation_ID(NewRec.getInt("ID") it's wrote in the code above ! – Omar Aug 18 '16 at 21:16
  • @Omar the default expression is if you do not send any parameter, you would need need to create a static method (or create the object in the expression) – Petter Friberg Aug 19 '16 at 08:43
  • @Petter Friberg ... I already did it but I need to test it yet ... I'll inform you if it successed – Omar Aug 19 '16 at 08:55
  • At last ... it works : in the Code : try{ Connect c=new Connect(); HashMap map = new HashMap(); map.put("Res_ID", Vars.get_Newest_Reservation_ID()); String Report="src\\voucherexpress\\ReservationReport.jrxml"; JasperReport jasp_rep=JasperCompileManager.compileReport(Report); JasperPrint jasp_print=JasperFillManager.fillReport(jasp_rep, map,c.Connstr); JasperViewer.viewReport(jasp_print); }catch(Exception ex){ JOptionPane.showMessageDialog(null, ex); } – Omar Aug 19 '16 at 13:28
  • Using hashmap() was very useful ... thank you guys – Omar Aug 19 '16 at 13:30

0 Answers0