You need to sign in to do that
Don't have an account?
Dritter
java DAQ class and getAllOrders() method
I have been writing a little APEX, but I was told it would be a good idea to learn JAVA before I continue with APEX. I created a JAVA application and I have a MySQL server / database to connect to. I created an Order Class, OrderDAO Class, and a ConnectionPOOL class. The Order class is the pojo. I'm trying to write a getAllOrders () method in the OrderDAO class (and UPDATE and DELETE), but I can't seem to get it to work. Would anyone mind taking a look?
ConnectionPool
OrderDAO
package com.douglas.myproject.pojo; import java.sql.Date; //import java.util.Date; public class Order{ private Integer id; private String name; private Date createdDate; public Order(){ } //constructor public Order (Integer id, String name, Date createdDate) { id = this.id; name = this.name; createdDate = this.createdDate; } //Get Method for the id public Integer getOrderId(){ return id; } //Set Method for the id public void setOrderId(Integer id){ this.id = id; } //Get Method for the Name public String getName() { return name; } //Set method for the Name public void setName(String name) { this.name = name; } //Get Method for the CreatedDate public Date getCreatedDate() { return createdDate; } //Get Method for the CreatedDate public void setCreatedDate(Date createdDate) { this.createdDate = createdDate; } }
ConnectionPool
package com.douglas.myproject.dao.driver; import java.sql.Connection; import java.sql.DriverManager; //import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class MyConnectionPool { private static String url = "jdbc:mysql://localhost:3306/Employee"; private static String username = "root"; private static String password = "kaplan"; public static Connection getConn() throws SQLException { Connection con = null; try { con = DriverManager.getConnection(url, username, password); } catch (SQLException e) { e.printStackTrace(); } return con; } /*** public void getRecords() { ResultSet rs = null; try { Statement s = getConn().createStatement(); rs = s.executeQuery("SELECT * FROM ORDER.order"); } catch (SQLException e) { System.out.println(e.getMessage()); } } **/ }
OrderDAO
package com.douglas.myproject.dao; import java.sql.ResultSet; import java.util.ArrayList; import java.util.List; import com.douglas.myproject.pojo.Order; import com.mysql.jdbc.Statement; public class OrderDAO { ResultSet myRs = null; Statement s = null; public List<Order> getAllOrders(){ //Statement s = getConn().createStatement(); List<Order> myRs = new ArrayList<Order>(); //ResultSet myRs = s.executeQuery("SELECT * FROM ORDER.order"); int i = 0; while (i < myRs.size()) { Order o = new Order(); myRs.add(o); i++; //System.out.println(myRs.getString("id") + ", " + myRs.getString("name") + ", " + myRs.getString("createdDate")); } return myRs; } public Boolean save(Order o) { return null; } public Boolean update(Order o) { return null; } public void delete(Order o) { } }