Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package comm;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.sql.Statement;
- import objects.*;
- import resources.Log;
- public class SQLadd{
- /**
- * Adds an order
- */
- public SQLadd(Order order){
- try{
- Log.msg("Adding order to database");
- Statement st = getConnection().createStatement();
- Log.msg("Order Info "+order.toString());
- st.executeUpdate("INSERT INTO order (user, product, ostatus, odate, name, address, phone)" +
- "VALUES('" + order.getUser() + "', '" + order.getProduct() +
- "', '" + order.getStatus() + "', '" + order.getDate()+ "', '" + order.getName()+
- "', '" +order.getAddress()+ "', '" + order.getPhone() +"');");
- } catch (SQLException e) {
- // Could not connect to the database
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- /**
- * Adds a warranty
- */
- public SQLadd(Warranty warrant){
- }
- /**
- * Adds a comment
- */
- public SQLadd(Comment comment){
- }
- /**
- * Adds a user
- */
- public SQLadd(User user){
- }
- /**
- * Creates mySQL connection
- * @throws ClassNotFoundException
- * @throws SQLException
- */
- public Connection getConnection() throws ClassNotFoundException, SQLException{
- String driver = "com.mysql.jdbc.Driver";
- String connection = "jdbc:mysql://localhost:3306/myDatabase";
- String user = "myUser";
- String password = "myPassword";
- Class.forName(driver);
- return DriverManager.getConnection(connection, user, password);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement