Advertisement
Guest User

Untitled

a guest
Apr 4th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. cusId orderId itemId
  2. 00006 00003 002
  3. 00006 00003 006
  4. 00007 00001 001
  5. 00007 00001 003
  6. 00007 00004 003
  7. 00008 00002 001
  8. 00008 00002 009
  9.  
  10. 002 006 -2
  11. 001 003 -1 003 -2
  12. 001 009 -2
  13.  
  14. public class Testing {
  15. public static void main(String[] args) {
  16. List data = new ArrayList();
  17. try {
  18. Connection con = null;
  19. Class.forName("com.mysql.jdbc.Driver");
  20. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/testing", "root", "");
  21. Statement st = con.createStatement();
  22. String query = "Select * from `order_item` as order_item left join `order` as order1 on order_item.orderId=order1.orderId order by order1.cusId, order_item.completedTime ";
  23. ResultSet rs = st.executeQuery(query);
  24.  
  25. while (rs.next()) {
  26. String cusId = rs.getString("cusId");
  27. String orderId = rs.getString("orderId");
  28. String itemId = rs.getString("itemId");
  29. data.add(cusId + " " + orderId + " " + itemId);
  30. }
  31.  
  32. writeToFile(data, "output.txt");
  33. rs.close();
  34. st.close();
  35. } catch (Exception e) {
  36. System.out.println(e);
  37. }
  38. }
  39.  
  40. private static void writeToFile(java.util.List list, String path) {
  41. BufferedWriter out = null;
  42. try {
  43. File file = new File(path);
  44. out = new BufferedWriter(new FileWriter(file, true));
  45. for (Object s : list) {
  46. out.write((String) s);
  47. out.newLine();
  48. }
  49. out.close();
  50. } catch (IOException e) {
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement