以下java代码显示从数据库表到jasper报告的所选记录显示所有其他记录不显示Customer表的第一行。
请任何有解决方案的人请分享我有两天这个但是我还没有得到解决方案
这是完整的代码
public class Myreport {
DefaultTableModel tableModel;
JTable table;
JFrame jframe;
public Myreport() {
Connection connection;
Statement stmt;
ResultSet rs;
try {
Class.forName("com.mysql.jdbc.Driver");
connection =DriverManager.getConnection("jdbc:mysql://localhost:3306/account","root","8000");
String query = "SELECT Cust_no, Cust_name, Gender, Address,Email,Stutus FROM Customer";
stmt = connection.createStatement();
rs = stmt.executeQuery(query);
JRResultSetDataSource rsdt = new JRResultSetDataSource(rs);
JasperReport jasperReport;
JasperPrint jasperPrint;
jasperReport = JasperCompileManager.compileReport("reports/report2.jrxml");
HashMap parameters = new HashMap();
rs.next();
String Cust_no = rs.getString("Cust_no");
String Cust_name = rs.getString("Cust_name");
String Gender = rs.getString("Gender");
String Address = rs.getString("Address");
String Email = rs.getString("Email");
String Stutus = rs.getString("Stutus");
parameters.put("Cust_no", Cust_no);
parameters.put("Cust_name", Cust_name);
parameters.put("Gender", Gender);
parameters.put("Address", Address);
parameters.put("Email", Email);
parameters.put("Stutus", Stutus);
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, rsdt);
JasperViewer view = new JasperViewer(jasperPrint);
view.setVisible(true);
System.out.println(rs);
connection.close();
} catch (ClassNotFoundException | SQLException | JRException ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, ex, "Error", JOptionPane.ERROR_MESSAGE);
}
}
public static void main(String[] args) {
new Myreport();
}
}
答案 0 :(得分:0)
我已经得到了答案我已经删除了这段代码
/* while(rs.next()){
// System.out.println(""+rs);
String Cust_no = rs.getString("Cust_no");
String Cust_name = rs.getString("Cust_name");
String Gender = rs.getString("Gender");
String Address = rs.getString("Address");
String Email = rs.getString("Email");
String Stutus = rs.getString("Stutus");
parameters.put("Cust_no", Cust_no);
parameters.put("Cust_name", Cust_name);
parameters.put("Gender", Gender);
parameters.put("Address", Address);
parameters.put("Email", Email);
parameters.put("Stutus", Stutus);
*/
现在所有行都显示在我的报告中