Advertisement
Guest User

Untitled

a guest
Jul 1st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. package comm;
  2.  
  3.  
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8.  
  9. import objects.*;
  10. import resources.Log;
  11.  
  12. public class SQLadd{
  13.     /**
  14.      * Adds an order
  15.      */
  16.     public SQLadd(Order order){
  17.         try{
  18.  
  19.             Log.msg("Adding order to database");
  20.             Statement st = getConnection().createStatement();
  21.             Log.msg("Order Info "+order.toString());
  22.            
  23.             st.executeUpdate("INSERT INTO order (user, product, ostatus, odate, name, address, phone)" +
  24.                     "VALUES('" + order.getUser() + "', '" + order.getProduct() +
  25.                     "', '" + order.getStatus() + "', '" + order.getDate()+ "', '" + order.getName()+
  26.                     "', '" +order.getAddress()+ "', '" + order.getPhone() +"');");
  27.            
  28.            
  29.            
  30.            
  31.         } catch (SQLException e) {
  32.             // Could not connect to the database
  33.             e.printStackTrace();
  34.         } catch (ClassNotFoundException e) {
  35.             // TODO Auto-generated catch block
  36.             e.printStackTrace();
  37.         }
  38.     }
  39.     /**
  40.      * Adds a warranty
  41.      */
  42.     public SQLadd(Warranty warrant){
  43.  
  44.     }
  45.     /**
  46.      * Adds a comment
  47.      */
  48.     public SQLadd(Comment comment){
  49.  
  50.     }
  51.     /**
  52.      * Adds a user
  53.      */
  54.     public SQLadd(User user){
  55.  
  56.     }
  57.     /**
  58.      * Creates mySQL connection
  59.      * @throws ClassNotFoundException
  60.      * @throws SQLException
  61.      */
  62.     public Connection getConnection() throws ClassNotFoundException, SQLException{
  63.     String driver = "com.mysql.jdbc.Driver";
  64.     String connection = "jdbc:mysql://localhost:3306/myDatabase";
  65.     String user = "myUser";
  66.     String password = "myPassword";
  67.     Class.forName(driver);
  68.     return DriverManager.getConnection(connection, user, password);
  69.     }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement