Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.Driver;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Statement;
- //import OrdersMapper.MyConnection;
- public class OrderMapper {
- static Connection theConn;
- public Order getOrderByTax(String tax) {
- Order ors = new Order();
- ors.setOrderDate("tzapa");
- try {
- theConn = MyConnection.getConnection();
- ResultSet rs;
- Statement stmt;
- String sql;
- sql = "select * from Orders";
- stmt = theConn.createStatement();
- rs = stmt.executeQuery(sql);
- while (rs.next()) {
- if (rs.getString("Taxes").equals(tax)) {
- /*String s1 = rs.getString("Order ID");
- String s2 = rs.getString("Employee ID");
- String s3 = rs.getString("Customer ID");
- String s4 = rs.getString("Order Date");
- String s5 = rs.getString("Shipped Date");
- String s6 = rs.getString("Shipper ID");
- String s7 = rs.getString("Ship State/Province");
- */
- String s4 = rs.getString("Order Date");
- //Orders ors = new Orders();
- ors.setOrderDate(s4);
- return ors;
- }
- }
- rs.close();
- stmt.close();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- finally {
- try {
- if (theConn != null) theConn.close();
- }
- catch (Exception e) {
- }
- }
- return ors;
- }
- public void createNewOrder(Order o){
- try {
- theConn = MyConnection.getConnection();
- ResultSet rs;
- Statement stmt;
- String sql;
- // sql = "INSERT INTO Orders (Taxes) values ('"+o.getTaxes()+"')";
- // sql = "INSERT INTO Orders (Taxes) values ('888')";
- sql = "UPDATE Employees SET Company = 'philtz' WHERE Taxes = '16'";
- stmt = theConn.createStatement();
- rs = stmt.executeQuery(sql);
- // rs = stmt.executeQuery(sql);
- rs.close();
- stmt.close();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- finally {
- try {
- if (theConn != null) theConn.close();
- }
- catch (Exception e) {
- }
- }
- }
- public static void main(String[] args) {
- OrderMapper om = new OrderMapper();
- Order o = om.getOrderByTax("19");
- System.out.println("cucu");
- System.out.println(o.getOrderDate());
- Order oo=new Order();
- oo.setOrderDate("77");
- oo.setTaxes(77);
- om.createNewOrder(oo);
- }
- static class MyConnection {
- public static Connection getConnection() throws Exception {
- Driver d = (Driver)Class.forName
- ("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
- Connection c = DriverManager.getConnection(
- "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:/TudicFilip/DISI/lab1.mdb"
- );
- return c;
- /*
- To use an already defined ODBC Datasource :
- String URL = "jdbc:odbc:myDSN";
- Connection c = DriverManager.getConnection(URL, "user", "pwd");
- */
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement