Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package Controller;
- import Model.Action;
- import Model.Thought;
- import java.sql.Connection;
- import java.sql.Date;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import miniproject.MainScreen;
- /**
- *
- * @author Ward
- */
- public class GTD {
- private ArrayList<Action> actions;
- private ArrayList<Thought> thoughts;
- private Connection con;
- private MainScreen screen;
- public GTD() throws SQLException{
- actions = new ArrayList<Action>();
- thoughts = new ArrayList<Thought>();
- con = DriverManager.getConnection("jdbc:mysql://databases.aii.avans.nl/wlaat_db", "wlaat", "CStP9D6j");
- screen = new MainScreen(this);
- getThoughts();
- getActions();
- screen.fillThoughtTable(thoughts);
- }
- public void insertThought(String thought) throws SQLException{
- Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE );
- ResultSet uprs = stmt.executeQuery("SELECT * FROM thought");
- uprs.moveToInsertRow();
- int i = thoughts.get(thoughts.size()-1).getThoughtID();
- i++;
- uprs.updateInt("thoughtID", i);
- uprs.updateString("thought", thought);
- uprs.insertRow();
- getThoughts();
- screen.fillThoughtTable(thoughts);
- }
- public void insertAction(String name, String description, Date date,String context,String project) throws SQLException{
- Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE );
- ResultSet uprs = stmt.executeQuery("SELECT * FROM action");
- uprs.moveToInsertRow();
- int i = actions.get(actions.size()-1).getActionID();
- i++;
- uprs.updateInt("actionID", i);
- uprs.updateString("name", name);
- uprs.updateString("context", context);
- uprs.updateString("project", project);
- uprs.updateString("description", description);
- uprs.updateDate("date", date);
- uprs.insertRow();
- getActions();
- screen.fillActionTable(actions);
- }
- public void deleteThought(int thoughtID) throws SQLException{
- Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE );
- ResultSet uprs = stmt.executeQuery("SELECT * FROM thought WHERE thoughtID = "+ thoughtID );
- uprs.first();
- uprs.deleteRow();
- getThoughts();
- }
- public void deleteAction(int actionID) throws SQLException{
- Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE );
- ResultSet uprs = stmt.executeQuery("SELECT * FROM action WHERE actionID = "+ actionID );
- uprs.first();
- uprs.deleteRow();
- getActions();
- }
- public void getThoughts() throws SQLException{
- Statement stmt = null;
- try {
- stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery("SELECT * FROM thought");
- while (rs.next()) {
- String s = rs.getString(1);
- int i = rs.getInt(2);
- thoughts.add(new Thought(s,i));
- System.out.println(s + i);
- }
- }
- catch(SQLException a){
- System.out.println(a);
- }
- }
- public void getActions() throws SQLException{
- Statement stmt = null;
- try {
- stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery("SELECT * FROM action");
- while (rs.next()) {
- String name = rs.getString(1);
- String desc = rs.getString(2);
- Date date = rs.getDate(3);
- String cont = rs.getString(4);
- String proj = rs.getString(5);
- int i = rs.getInt(6);
- actions.add(new Action(name, desc, date, cont, proj, i));
- System.out.println("" + name + ", " + desc + ", " + date + ", " + cont + ", " + proj + ", " + i);
- }
- }
- catch(SQLException a) {
- System.out.println(a);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement