が..私はそれがpdfファイルを保存したい従業員 の詳細が含まれていますが、それはpdfファイルを保存し、単に表示されていないです示すエラー「ます。java.sql.SQLException:結果セットの開始前に、」私のコードで
「ます。java.sql.SQLException:結果セットの開始前に」
は私がunderstanding..whatないメートル....助けが必要ですが、このコードの問題です。 結果セットを取り消し、preparedstatementに問題があると思います。
private void txt_searchKeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
try{
String sql ="select * from staff_info where id=? ";
pst=conn.prepareStatement(sql);
pst.setString(1,txt_search.getText());
rs=pst.executeQuery();
while(rs.next())
{
int add1 =rs.getInt("id");
txt_id.setText(add1+"");
String add2 =rs.getString("first_name");
txt_firstname.setText(add2);
String add3 =rs.getString("surname");
txt_surname.setText(add3);
String add4 =rs.getString("Dob");
txt_dob.setText(add4);
String add5 =rs.getString("Department");
txt_dep.setText(add5);
String add7 =rs.getString("Salary");
txt_salary.setText(add7);
String add8 =rs.getString("Status");
txt_status.setText(add8);
String add9 =rs.getString("Date_hired");
txt_doj.setText(add9);
String add10 =rs.getString("job_title");
txt_job.setText(add10);
String add17 =rs.getString("Designation");
txt_desig.setText(add17);
}
}catch(Exception e){
JOptionPane.showMessageDialog(null, "No Data");
}
finally {
try{
/* rs.close();
pst.close();*/
}
catch(Exception e){
}
}
}
private void txt_firstnameActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txt_jobActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void txt_salaryActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String value = txt_firstname.getText();
String value0 = txt_surname.getText();
String value1 = txt_id.getText();
String value2 = txt_desig.getText();
String value3 = txt_desig.getText();
JFileChooser dialog = new JFileChooser();
dialog.setSelectedFile(new File(value +" "+ value0+"-Salary Slip"+".pdf"));
int dialogResult = dialog.showSaveDialog(null);
if (dialogResult==JFileChooser.APPROVE_OPTION){
String filePath = dialog.getSelectedFile().getPath();
try {
// TODO add your handling code here:
for (int i=0; i<1000; i++) {
String sql ="select * from deductions where emp_id = '"+value1+"'";
pst=conn.prepareStatement(sql);
rs=pst.executeQuery();
String val = rs.getString(5);
String reason = rs.getString(6);
rs.close();
pst.close();
String sq ="select * from allowance where emp_id = '"+value1+"'";
pst=conn.prepareStatement(sq);
rs=pst.executeQuery();
int calcTotal = Integer.parseInt(txt_salary.getText());
float x = Float.valueOf(rs.getString(9));
int v = Integer.parseInt(val);
float total = calcTotal+ x -v;
Document myDocument = new Document();
PdfWriter myWriter = PdfWriter.getInstance(myDocument, new FileOutputStream(filePath));
myDocument.open();
myDocument.add(new Paragraph("PAY SLIP",FontFactory.getFont(FontFactory.TIMES_BOLD,20,Font.BOLD)));
myDocument.add(new Paragraph(new Date().toString()));
myDocument.add(new Paragraph("-------------------------------------------------------------------------------------------"));
myDocument.add((new Paragraph("EMPLOYEE DETAILS",FontFactory.getFont(FontFactory.TIMES_ROMAN,15,Font.BOLD))));
myDocument.add((new Paragraph("Name of Employee: " +value + " "+value0,FontFactory.getFont(FontFactory.TIMES_ROMAN,10,Font.PLAIN))));
myDocument.add((new Paragraph("Designation: "+value2,FontFactory.getFont(FontFactory.TIMES_ROMAN,10,Font.PLAIN))));
myDocument.add((new Paragraph("Department: "+value3,FontFactory.getFont(FontFactory.TIMES_ROMAN,10,Font.PLAIN))));
myDocument.add(new Paragraph("-------------------------------------------------------------------------------------------"));
myDocument.add(new Paragraph("SALARY",FontFactory.getFont(FontFactory.TIMES_ROMAN,15,Font.BOLD)));
myDocument.add(new Paragraph("Basic Salary: $"+calcTotal,FontFactory.getFont(FontFactory.TIMES_ROMAN,10,Font.PLAIN)));
myDocument.add(new Paragraph("Overtime: "+rs.getString(2)+" Hours",FontFactory.getFont(FontFactory.TIMES_ROMAN,10,Font.PLAIN)));
myDocument.add(new Paragraph("Medical: $" +rs.getString(3),FontFactory.getFont(FontFactory.TIMES_ROMAN,10,Font.PLAIN)));
myDocument.add(new Paragraph("Bonus: $"+rs.getString(4),FontFactory.getFont(FontFactory.TIMES_ROMAN,10,Font.PLAIN)));
myDocument.add(new Paragraph("Other: $"+rs.getString(5),FontFactory.getFont(FontFactory.TIMES_ROMAN,10,Font.PLAIN)));
myDocument.add(new Paragraph("-------------------------------------------------------------------------------------------"));
myDocument.add(new Paragraph("DEDUCTION",FontFactory.getFont(FontFactory.TIMES_ROMAN,15,Font.BOLD)));
myDocument.add(new Paragraph("Deduction Details: "+reason,FontFactory.getFont(FontFactory.TIMES_ROMAN,10,Font.PLAIN)));
myDocument.add(new Paragraph("Total Deductions : $"+val ,FontFactory.getFont(FontFactory.TIMES_ROMAN,10,Font.PLAIN)));
myDocument.add(new Paragraph("-------------------------------------------------------------------------------------------"));
myDocument.add(new Paragraph("TOTAL PAYMENT",FontFactory.getFont(FontFactory.TIMES_ROMAN,15,Font.BOLD)));
myDocument.add(new Paragraph("Total Earnings: "+rs.getString(9),FontFactory.getFont(FontFactory.TIMES_ROMAN,10,Font.PLAIN)));
myDocument.add(new Paragraph("Net Pay : " +total,FontFactory.getFont(FontFactory.TIMES_ROMAN,10,Font.PLAIN)));
myDocument.add(new Paragraph("-------------------------------------------------------------------------------------------"));
myDocument.newPage();
myDocument.close();
JOptionPane.showMessageDialog(null,"Report was successfully generated");
}
}
catch(Exception e){
JOptionPane.showMessageDialog(null,e);
}
finally {
try{
rs.close();
pst.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(null,e);
}
}
}
}
とあなたはintとしてそれを治療している結果セット
で文字列としてではなく、それを処理しているあなたの結果はnullに設定されていますか? – CBredlow
あなたは正しいですが、rsが進む必要がある別のセクションがあります。 – CBredlow