Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cusId orderId itemId
- 00006 00003 002
- 00006 00003 006
- 00007 00001 001
- 00007 00001 003
- 00007 00004 003
- 00008 00002 001
- 00008 00002 009
- 002 006 -2
- 001 003 -1 003 -2
- 001 009 -2
- public class Testing {
- public static void main(String[] args) {
- List data = new ArrayList();
- try {
- Connection con = null;
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection("jdbc:mysql://localhost:3306/testing", "root", "");
- Statement st = con.createStatement();
- 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 ";
- ResultSet rs = st.executeQuery(query);
- while (rs.next()) {
- String cusId = rs.getString("cusId");
- String orderId = rs.getString("orderId");
- String itemId = rs.getString("itemId");
- data.add(cusId + " " + orderId + " " + itemId);
- }
- writeToFile(data, "output.txt");
- rs.close();
- st.close();
- } catch (Exception e) {
- System.out.println(e);
- }
- }
- private static void writeToFile(java.util.List list, String path) {
- BufferedWriter out = null;
- try {
- File file = new File(path);
- out = new BufferedWriter(new FileWriter(file, true));
- for (Object s : list) {
- out.write((String) s);
- out.newLine();
- }
- out.close();
- } catch (IOException e) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement