Advertisement
Guest User

Untitled

a guest
Sep 9th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. <%@page import="java.sql.*"%>
  2. <%@page import="java.sql.SQLException"%>
  3. <%@page import="org.apache.poi.hssf.usermodel.*"%>
  4. <%@page import=" java.io.*"%>
  5.  
  6. <%
  7.  
  8. String url = "jdbc:mysql://localhost:3306/";
  9. String dbName = "login";
  10. String driver = "com.mysql.jdbc.Driver";
  11. String userName = "root";
  12. String password = "";
  13. try {
  14. Class.forName("driver");
  15. Connection con = DriverManager.getConnection("url + dbName", "userName",
  16. "password");
  17. Statement st = con.createStatement();
  18. ResultSet rs = st.executeQuery("select * from openstock");
  19. HSSFWorkbook workbook = new HSSFWorkbook();
  20. HSSFSheet sheet = workbook.createSheet("fisocon");
  21. HSSFRow rowhead = sheet.createRow((short) 0);
  22. rowhead.createCell((short) 0).setCellValue("iname");
  23. rowhead.createCell((short) 1).setCellValue("wname");
  24. rowhead.createCell((short) 2).setCellValue("catname");
  25. rowhead.createCell((short) 3).setCellValue("class");
  26. rowhead.createCell((short) 4).setCellValue("unit");
  27. rowhead.createCell((short) 5).setCellValue("nname");
  28. int i = 1;
  29.  
  30. while (rs.next()){
  31. out.println("hai2");
  32. HSSFRow row = sheet.createRow((short) i);
  33. row.createCell((short)
  34. 0).setCellValue(Integer.toString(rs.getInt("iname")));
  35. row.createCell((short) 1).setCellValue(rs.getString("wname"));
  36. row.createCell((short) 2).setCellValue(rs.getString("catname"));
  37. row.createCell((short) 3).setCellValue(rs.getString("class"));
  38. row.createCell((short) 4).setCellValue(rs.getString("unit"));
  39. row.createCell((short) 5).setCellValue(rs.getString("nname"));
  40. i++;
  41. }
  42. String yemi = "d:/xls/test.xls";
  43. FileOutputStream fileOut = new FileOutputStream(yemi);
  44. workbook.write(fileOut);
  45. fileOut.close();
  46. } catch (ClassNotFoundException e1) {
  47. e1.printStackTrace();
  48. }
  49. catch (SQLException e1) {
  50. e1.printStackTrace();
  51. } catch (FileNotFoundException e1) {
  52. e1.printStackTrace();
  53. } catch (IOException e1) {
  54. e1.printStackTrace();
  55. }
  56. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement