Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement