Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. public void writeText()
  2. {
  3. try
  4. {
  5. Class.forName("com.mysql.jdbc.Driver");
  6. }
  7. catch(Exception e)
  8. {
  9. e.printStackTrace();
  10. }
  11. final String DB_URL ="jdbc:mysql://mis-sql.uhcl.edu/gattupalliv3940";
  12. Connection conn = null;
  13. Statement stat = null;
  14. ResultSet rs = null;
  15. try
  16. {
  17. conn = DriverManager.getConnection(DB_URL,"gattupalliv3940","1552688");
  18. stat = conn.createStatement();
  19. rs = stat.executeQuery("select * from student_2");
  20. FileWriter fw = new FileWriter("data.txt");
  21. BufferedWriter bw = new BufferedWriter(fw);
  22. String line ="";
  23. while(rs.next())
  24. {
  25. line = rs.getInt(1)+"t"+rs.getString(2)+"t"+rs.getDouble(3);
  26. bw.write(line);
  27. bw.newLine();
  28. }
  29. bw.close();
  30. }
  31. catch(Exception e)
  32. {
  33. e.printStackTrace();
  34. }
  35. finally
  36. {
  37. try
  38. {
  39. conn.close();
  40. rs.close();
  41. stat.close();
  42. }
  43. catch(Exception e)
  44. {
  45. e.printStackTrace();
  46. }
  47. }
  48. }
  49.  
  50. @RequestMapping(value="/")
  51. public ModelAndView test(HttpServletRequest request, HttpServletResponse response) throws IOException{
  52.  
  53. writeText(request.getRealPath("data.txt"));
  54.  
  55. return new ModelAndView("home");
  56. }
  57.  
  58. public void writeText(String path) {
  59. BufferedWriter bw = null;
  60. try {
  61. FileWriter fw = new FileWriter(path);
  62. bw = new BufferedWriter(fw);
  63. String line = "this is only a test";
  64. bw.write(line);
  65. bw.newLine();
  66. }
  67. catch(Exception e) {
  68. e.printStackTrace();
  69. } finally {
  70. if( bw != null ) {
  71. try {
  72. bw.close();
  73. } catch (IOException e) {
  74. // ignore
  75. }
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement