Skip to content
Browse files

removed id from users and added new database tables

  • Loading branch information...
1 parent 0f7cf01 commit e8b0f2dbcdc4b56466b87b1bad5b941fd32c2bd8 @wesleyk committed
View
BIN hw9/bin/edu/cmu/cs214/hw9/db/Constants.class
Binary file not shown.
View
BIN hw9/bin/edu/cmu/cs214/hw9/db/SQLiteAdapter.class
Binary file not shown.
View
BIN hw9/bin/edu/cmu/cs214/hw9/db/User.class
Binary file not shown.
View
BIN hw9/bin/edu/cmu/cs214/hw9/db/UserDAO.class
Binary file not shown.
View
3 hw9/src/edu/cmu/cs214/hw9/db/Constants.java
@@ -5,4 +5,7 @@
public static final String JDBC_NAME = "org.sqlite.JDBC";//Java database connectivity driver for sqlite
public static final int TIMEOUT = 30000;
public static final String USERS_TABLE = "Users";
+ public static final String POSTS_TABLE = "Posts";
+ public static final String FRIENDS_TABLE = "Friends";
+ public static final String SUBSCRIPTIONS_TABLE = "Subscriptions";
}
View
9 hw9/src/edu/cmu/cs214/hw9/db/SQLiteAdapter.java
@@ -15,8 +15,13 @@ public void createTables(){
Statement stat;
try {
stat = conn.createStatement();
- //Table name //field //field //field //field
- stat.executeUpdate("CREATE TABLE " + Constants.USERS_TABLE + " (id integer PRIMARY KEY, email varchar(50), name varchar(50), password varchar(50));");
+
+ // Create the four tables: users, posts, friends, and subscriptions
+ stat.executeUpdate("CREATE TABLE " + Constants.USERS_TABLE + " (email varchar(50) PRIMARY KEY, name varchar(50), password varchar(50));");
+ stat.executeUpdate("CREATE TABLE " + Constants.POSTS_TABLE + " (email varchar(50) PRIMARY KEY, content varchar(200), is_post boolean, date_added date());");
+ stat.executeUpdate("CREATE TABLE " + Constants.FRIENDS_TABLE + " (email1 varchar(50) PRIMARY KEY, email2 varchar(50));");
+ stat.executeUpdate("CREATE TABLE " + Constants.SUBSCRIPTIONS_TABLE + " (email1 varchar(50) PRIMARY KEY, email2 varchar(50));");
+
/*PreparedStatement ps;
String statement = "INSERT INTO " + Constants.USERS_TABLE + " (email, password, name) VALUES (?, ?, ?)";
View
8 hw9/src/edu/cmu/cs214/hw9/db/User.java
@@ -1,13 +1,11 @@
package edu.cmu.cs214.hw9.db;
public class User {
- private int id;
private String email;
private String password;
private String name;
- public User(int id, String email, String password, String name){
- this.id = id;
+ public User(String email, String password, String name){
this.email = email;
this.password = password;
this.name = name;
@@ -21,10 +19,6 @@ public String getPassword(){
return password;
}
- public int getID(){
- return id;
- }
-
public String getName(){
return name;
}
View
4 hw9/src/edu/cmu/cs214/hw9/db/UserDAO.java
@@ -17,7 +17,7 @@ public UserDAO() throws Exception{
try {
while(rs.next()){
- ret.add(new User(rs.getInt("id"), rs.getString("email"), rs.getString("password"), rs.getString("name")));
+ ret.add(new User(rs.getString("email"), rs.getString("password"), rs.getString("name")));
}
} catch (SQLException e) {
e.printStackTrace();
@@ -43,7 +43,7 @@ public User findUser(String email){
System.out.println("user not found in database (in User.DAO.java)");
return null;
}
- ret = new User(rs.getInt("id"), rs.getString("email"), rs.getString("password"), rs.getString("name"));
+ ret = new User(rs.getString("email"), rs.getString("password"), rs.getString("name"));
} catch (SQLException e) {
e.printStackTrace();
} finally {

0 comments on commit e8b0f2d

Please sign in to comment.
Something went wrong with that request. Please try again.