Get Datebase in Excel sheet.


 try
        {
            Class.forName("com.mysql.jdbc.Driver");
            java.sql.Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3305/commity","root","root");
            String sql="select Group_Number,MemberName,Payment,Date,Withdraw from insatllment";
            PreparedStatement pst=(PreparedStatement) con.prepareStatement(sql);
            ResultSet rs=pst.executeQuery();
          HSSFRow rowhead = sheet.createRow((short)0);
rowhead.createCell((short) 0).setCellValue("Group_Number");
rowhead.createCell((short) 1).setCellValue("MemberName");
rowhead.createCell((short) 2).setCellValue("Payment");
rowhead.createCell((short) 3).setCellValue("Date");
rowhead.createCell((short) 4).setCellValue("Withdraw");

int index=1;

while(rs.next())
{
HSSFRow row = sheet.createRow((short)index);
row.createCell((short) 0).setCellValue(rs.getString(1).toString());
row.createCell((short) 1).setCellValue(rs.getString(2).toString());
row.createCell((short) 2).setCellValue(rs.getDouble(3));
row.createCell((short) 3).setCellValue(rs.getDate(4).toString());
row.createCell((short) 4).setCellValue(rs.getString(5).toString());
index++;
}
FileOutputStream fileOut = new FileOutputStream("h://installment.xls");
wb.write(fileOut);
fileOut.close();
//Runtime rt = Runtime.getRuntime();
//rt.exec("cmd.exe /h start h:\\Member.xls");
Desktop.getDesktop().open(new File("h://installment.xls"));
          
  con.close();
  pst.close();
        }
        catch(Exception e)
        {
            System.out.println(e);
        }

Popular posts from this blog

Simple Sign up design. Android.

Cart page design in android.

Set Date on jDateChooser and retrieve record from database.