├── .vscode ├── launch.json └── settings.json ├── README.md ├── lib └── mysql-connector-java-8.0.23.jar └── src ├── App.java ├── Book.java ├── BooksUtility.java ├── DB.java ├── Menu.java ├── User.java ├── UsersUtility.java └── Utils.java /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "java", 9 | "name": "Launch App", 10 | "request": "launch", 11 | "mainClass": "App", 12 | "projectName": "library-management-java_805bd866" 13 | }, 14 | { 15 | "type": "java", 16 | "name": "Launch App", 17 | "request": "launch", 18 | "mainClass": "App", 19 | "projectName": "libraryManagement_fa23727c" 20 | }, 21 | { 22 | "type": "java", 23 | "name": "Launch App", 24 | "request": "launch", 25 | "mainClass": "App", 26 | "projectName": "libraryManagement_a588ee11" 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "java.project.referencedLibraries": [ 3 | "lib/**/*.jar", 4 | "mysql-connector-java-8.0.23.jar" 5 | ] 6 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Library Management Project 2 | 3 | ## Author - Bihan Chakraborty 4 | 5 | ### Steps to run 6 | 7 | - Open project in any editor 8 | - Configure jar paths 9 | - Run project 10 | 11 | Note: Java version used for this project: java 16 2021-03-16 12 | -------------------------------------------------------------------------------- /lib/mysql-connector-java-8.0.23.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Bihan001/library-management-java/ae112028b5b126c558d6445741e180cd1982c7ce/lib/mysql-connector-java-8.0.23.jar -------------------------------------------------------------------------------- /src/App.java: -------------------------------------------------------------------------------- 1 | /** 2 | * App 3 | */ 4 | public class App { 5 | public static void main(String[] args) { 6 | // Initialising the database 7 | DB db = new DB(); 8 | 9 | // String test = String.format("test goes here %s more text", "Testing"); 10 | db.createUsersTable(); 11 | db.createBooksTable(); 12 | 13 | // Generating mock data for testing, not required in production. 14 | // MockData md = new MockData(); 15 | // md.generate(db); 16 | 17 | // Initialising utility classes for accessing all the utility functions. 18 | UsersUtility usersUtility = new UsersUtility(db); 19 | BooksUtility booksUtility = new BooksUtility(db); 20 | 21 | // Main menu 22 | Menu menu = new Menu(usersUtility, booksUtility); 23 | menu.runMainMenu(); 24 | } 25 | } -------------------------------------------------------------------------------- /src/Book.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | 3 | public class Book { 4 | private String id; 5 | private String name; 6 | private String author; 7 | private int count; 8 | private ArrayList genre; 9 | 10 | Book(String id, String name, String author, int count, ArrayList genre) { 11 | this.id = id; 12 | this.name = name; 13 | this.author = author; 14 | this.genre = genre; 15 | this.count = count; 16 | } 17 | 18 | public String getId() { 19 | return this.id; 20 | } 21 | 22 | public int getCount() { 23 | return this.count; 24 | } 25 | 26 | public void setCount(int count) { 27 | this.count = count; 28 | } 29 | 30 | public Book updateBook(String name, String author, int count, ArrayList genre) { 31 | if (!name.isBlank()) 32 | this.name = name; 33 | if (!author.isBlank()) 34 | this.author = author; 35 | if (!genre.isEmpty()) 36 | this.genre = genre; 37 | if (this.count >= 0) 38 | this.count = count; 39 | return this; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return this.id + ", " + this.name + ", " + this.author + ", " + this.count + ", " + this.genre; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/BooksUtility.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | import java.util.ArrayList; 4 | 5 | public class BooksUtility { 6 | private DB db; 7 | private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 8 | 9 | BooksUtility(DB db) { 10 | this.db = db; 11 | } 12 | 13 | public void createBook() { 14 | try { 15 | String name, author, genre; 16 | int count = -1; 17 | System.out.println("Create new book:"); 18 | System.out.print("Enter name: "); 19 | name = br.readLine(); 20 | System.out.print("Enter author: "); 21 | author = br.readLine(); 22 | System.out.print("Enter book count: "); 23 | count = Integer.parseInt(br.readLine()); 24 | if (count < 0) { 25 | count = 0; 26 | } 27 | System.out.print("Enter genres(Seperate with ','): "); 28 | genre = br.readLine(); 29 | Book newBook = db.createBook(name, author, count, genre); 30 | System.out.println(newBook.toString()); 31 | } catch (Exception e) { 32 | System.out.println(e); 33 | } 34 | } 35 | 36 | public void getBook() { 37 | try { 38 | String id; 39 | System.out.println("Get book details:"); 40 | System.out.print("Enter book id: "); 41 | id = br.readLine(); 42 | Book book = db.readBookByField("id", id); 43 | System.out.println(book.toString()); 44 | } catch (Exception e) { 45 | System.out.println(e); 46 | } 47 | } 48 | 49 | public void updateBook() { 50 | try { 51 | String id, name, author, genre; 52 | int count = -1; 53 | System.out.println("Update book:"); 54 | System.out.print("Enter book id: "); 55 | id = br.readLine(); 56 | System.out.print("Enter name: "); 57 | name = br.readLine(); 58 | System.out.print("Enter author: "); 59 | author = br.readLine(); 60 | System.out.print("Enter book count: "); 61 | String countInput = br.readLine(); 62 | if (!countInput.isBlank()) 63 | Integer.parseInt(countInput); 64 | if (count < 0) { 65 | count = 0; 66 | } 67 | System.out.print("Enter genres(Seperate with ','): "); 68 | genre = br.readLine(); 69 | Book book = db.updateBook(id, name, author, count, genre); 70 | System.out.println(book.toString()); 71 | } catch (Exception e) { 72 | System.out.println(e); 73 | } 74 | } 75 | 76 | public void deleteBook() { 77 | try { 78 | String id; 79 | System.out.println("Delete book:"); 80 | System.out.print("Enter book id: "); 81 | id = br.readLine(); 82 | db.deleteBook(id); 83 | System.out.println("Deleted book with id: " + id); 84 | } catch (Exception e) { 85 | System.out.println(e); 86 | } 87 | } 88 | 89 | public void getAllBooks() { 90 | try { 91 | System.out.println("All book details:"); 92 | ArrayList books = db.getAllBooks(); 93 | books.forEach((book) -> System.out.println(book.toString())); 94 | } catch (Exception e) { 95 | System.out.println(e); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/DB.java: -------------------------------------------------------------------------------- 1 | import java.sql.Connection; 2 | import java.sql.DriverManager; 3 | import java.sql.PreparedStatement; 4 | import java.sql.ResultSet; 5 | import java.util.ArrayList; 6 | 7 | public class DB { 8 | private Connection connection; 9 | 10 | DB() { 11 | this.connection = getConnection(); 12 | } 13 | 14 | public void createUsersTable() { 15 | try { 16 | String query = "CREATE TABLE IF NOT EXISTS users(id int NOT NULL AUTO_INCREMENT, name varchar(255), phone varchar(255), email varchar(255) UNIQUE, address varchar(255), current_books varchar(255), PRIMARY KEY(id))"; 17 | Utils.execUpdate(this.connection, query); 18 | } catch (Exception e) { 19 | System.out.println(e); 20 | } 21 | } 22 | 23 | public void createBooksTable() { 24 | try { 25 | String query = "CREATE TABLE IF NOT EXISTS books(id int NOT NULL AUTO_INCREMENT, name varchar(255), author varchar(255), count int, genres varchar(255), PRIMARY KEY(id))"; 26 | Utils.execUpdate(this.connection, query); 27 | } catch (Exception e) { 28 | System.out.println(e); 29 | } 30 | } 31 | 32 | public ArrayList getAllUsers() { 33 | ArrayList users = new ArrayList(); 34 | try { 35 | String query = "SELECT * from users"; 36 | ResultSet res = Utils.execQuery(this.connection, query); 37 | while (res.next()) { 38 | User user = new User(res.getString("id"), res.getString("name"), res.getString("phone"), 39 | res.getString("email"), res.getString("address"), res.getString("current_books")); 40 | users.add(user); 41 | } 42 | return users; 43 | } catch (Exception e) { 44 | System.out.println(e); 45 | return users; 46 | } 47 | } 48 | 49 | public User readUserByField(String field, String value) { 50 | try { 51 | String query = String.format("SELECT * FROM users WHERE %s='%s'", field, value); 52 | ResultSet res = Utils.execQuery(this.connection, query); 53 | while (res.next()) { 54 | User user = new User(res.getString("id"), res.getString("name"), res.getString("phone"), 55 | res.getString("email"), res.getString("address"), res.getString("current_books")); 56 | return user; 57 | } 58 | return null; 59 | } catch (Exception e) { 60 | System.out.println(e); 61 | return null; 62 | } 63 | } 64 | 65 | public User createUser(String name, String phone, String email, String address) { 66 | try { 67 | if (name.isBlank() || phone.isBlank()) 68 | return null; 69 | String query = String.format( 70 | "INSERT INTO users(name, phone, email, address, current_books) VALUES ('%s','%s','%s','%s', '%s');", 71 | name, phone, email, address, ""); 72 | PreparedStatement p = this.connection.prepareStatement(query); 73 | p.executeUpdate(); 74 | return readUserByField("email", email); 75 | } catch (Exception e) { 76 | System.out.println(e); 77 | return null; 78 | } 79 | } 80 | 81 | public User updateUser(String id, String name, String phone, String email, String address) { 82 | if (id.isBlank()) 83 | return null; 84 | String query = String.format("UPDATE users SET %s %s %s %s WHERE id='%s'", 85 | !name.isBlank() ? "name=" + "'" + name + "'," : "", 86 | !phone.isBlank() ? "phone=" + "'" + phone + "'," : "", 87 | !email.isBlank() ? "email=" + "'" + email + "'," : "", 88 | !address.isBlank() ? "address=" + "'" + address + "'" : "", id); 89 | Utils.execUpdate(this.connection, query); 90 | return readUserByField("id", id); 91 | } 92 | 93 | public void deleteUser(String id) { 94 | String query = String.format("DELETE FROM users WHERE id='%s'", id); 95 | Utils.execUpdate(this.connection, query); 96 | } 97 | 98 | public void assignBookToUser(String userId, String bookId) { 99 | User user = readUserByField("id", userId); 100 | Book book = readBookByField("id", bookId); 101 | if (user == null || book == null) 102 | return; 103 | ArrayList currentBooks = Utils.getArrayListFromString(user.getCurrentBooks()); 104 | if (currentBooks.contains(bookId)) 105 | return; 106 | currentBooks.add(bookId); 107 | String currentBooksStr = String.join(",", currentBooks); 108 | String query = String.format("UPDATE users SET current_books='%s' WHERE id='%s'", currentBooksStr, userId); 109 | Utils.execUpdate(connection, query); 110 | } 111 | 112 | public void revokeBookFromUser(String userId, String bookId) { 113 | User user = readUserByField("id", userId); 114 | Book book = readBookByField("id", bookId); 115 | if (user == null || book == null) 116 | return; 117 | ArrayList currentBooks = Utils.getArrayListFromString(user.getCurrentBooks()); 118 | if (!currentBooks.contains(bookId)) 119 | return; 120 | currentBooks.remove(bookId); 121 | String currentBooksStr = String.join(",", currentBooks); 122 | String query = String.format("UPDATE users SET current_books='%s' WHERE id='%s'", currentBooksStr, userId); 123 | Utils.execUpdate(connection, query); 124 | } 125 | 126 | // Books 127 | 128 | public ArrayList getAllBooks() { 129 | ArrayList books = new ArrayList(); 130 | try { 131 | String query = "SELECT * from books"; 132 | ResultSet res = Utils.execQuery(this.connection, query); 133 | while (res.next()) { 134 | ArrayList genres = Utils.getArrayListFromString(res.getString("genres")); 135 | Book book = new Book(res.getString("id"), res.getString("name"), res.getString("author"), 136 | res.getInt("count"), genres); 137 | books.add(book); 138 | } 139 | return books; 140 | } catch (Exception e) { 141 | System.out.println(e); 142 | return books; 143 | } 144 | } 145 | 146 | public Book readBookByField(String field, String value) { 147 | try { 148 | String query = String.format("SELECT * FROM books WHERE %s='%s'", field, value); 149 | ResultSet res = Utils.execQuery(this.connection, query); 150 | while (res.next()) { 151 | ArrayList genres = Utils.getArrayListFromString(res.getString("genres")); 152 | Book book = new Book(res.getString("id"), res.getString("name"), res.getString("author"), 153 | res.getInt("count"), genres); 154 | return book; 155 | } 156 | return null; 157 | } catch (Exception e) { 158 | System.out.println(e); 159 | return null; 160 | } 161 | } 162 | 163 | public Book createBook(String name, String author, int count, String genre) { 164 | try { 165 | if (name.isBlank() || author.isBlank()) 166 | return null; 167 | String query = String.format("INSERT INTO books(name, author, count, genres) VALUES ('%s','%s','%s','%s');", 168 | name, author, count, genre); 169 | PreparedStatement p = this.connection.prepareStatement(query); 170 | p.executeUpdate(); 171 | return readBookByField("name", name); 172 | } catch (Exception e) { 173 | System.out.println(e); 174 | return null; 175 | } 176 | } 177 | 178 | public Book updateBook(String id, String name, String author, int count, String genre) { 179 | if (id.isBlank()) 180 | return null; 181 | String query = String.format("UPDATE books SET %s %s %s %s WHERE id='%s'", 182 | !name.isBlank() ? "name=" + "'" + name + "'," : "", 183 | !author.isBlank() ? "author=" + "'" + author + "'," : "", 184 | count >= 0 ? "count=" + "'" + count + "'," : "", !genre.isBlank() ? "genres=" + "'" + genre + "'" : "", 185 | id); 186 | Utils.execUpdate(this.connection, query); 187 | return readBookByField("id", id); 188 | } 189 | 190 | public void deleteBook(String id) { 191 | String query = String.format("DELETE FROM books WHERE id='%s'", id); 192 | Utils.execUpdate(this.connection, query); 193 | } 194 | 195 | public Connection getConnection() { 196 | try { 197 | String driver = "com.mysql.cj.jdbc.Driver"; 198 | String url = "jdbc:mysql://remotemysql.com:3306/4ERVN96YDC"; 199 | String username = "4ERVN96YDC"; 200 | String password = "ZNBlGkhQUf"; 201 | Class.forName(driver); 202 | 203 | Connection conn = DriverManager.getConnection(url, username, password); 204 | System.out.println("Connected"); 205 | return conn; 206 | } catch (Exception e) { 207 | System.out.println(e); 208 | } 209 | 210 | return null; 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /src/Menu.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Menu { 4 | private UsersUtility usersUtility; 5 | private BooksUtility booksUtility; 6 | 7 | Menu(UsersUtility usersUtility, BooksUtility booksUtility) { 8 | this.usersUtility = usersUtility; 9 | this.booksUtility = booksUtility; 10 | } 11 | 12 | public void runMainMenu() { 13 | Scanner sc = new Scanner(System.in); 14 | mainMenu(sc); 15 | sc.close(); 16 | } 17 | 18 | private void mainMenu(Scanner sc) { 19 | int option; 20 | System.out.println("1. Books"); 21 | System.out.println("2. Users"); 22 | System.out.println("3. Exit"); 23 | System.out.print("Select an option: "); 24 | option = sc.nextInt(); 25 | boolean shouldExit = false; 26 | if (option == 1) 27 | booksMenu(sc); 28 | else if (option == 2) 29 | usersMenu(sc); 30 | else if (option == 3) 31 | shouldExit = true; 32 | else 33 | System.out.println("Wrong option!"); 34 | System.out.println(); 35 | if (shouldExit) 36 | return; 37 | mainMenu(sc); 38 | } 39 | 40 | private void booksMenu(Scanner sc) { 41 | int option; 42 | System.out.println("1. Create book"); 43 | System.out.println("2. Read book"); 44 | System.out.println("3. Update book"); 45 | System.out.println("4. Delete book"); 46 | System.out.println("5. Display all books"); 47 | System.out.println("6. Back"); 48 | System.out.print("Select an option: "); 49 | option = sc.nextInt(); 50 | boolean shouldExit = false; 51 | switch (option) { 52 | case 1: 53 | // Create book 54 | booksUtility.createBook(); 55 | break; 56 | case 2: 57 | // Read book 58 | booksUtility.getBook(); 59 | break; 60 | case 3: 61 | // Update book 62 | booksUtility.updateBook(); 63 | break; 64 | case 4: 65 | // Delete book 66 | booksUtility.deleteBook(); 67 | break; 68 | case 5: 69 | // Display all books 70 | booksUtility.getAllBooks(); 71 | break; 72 | case 6: 73 | shouldExit = true; 74 | break; 75 | default: 76 | // Wrong option 77 | System.out.println("Wrong option!"); 78 | break; 79 | } 80 | System.out.println(); 81 | if (shouldExit) 82 | return; 83 | booksMenu(sc); 84 | } 85 | 86 | private void usersMenu(Scanner sc) { 87 | int option; 88 | System.out.println("1. Create user"); 89 | System.out.println("2. Read user"); 90 | System.out.println("3. Update user"); 91 | System.out.println("4. Delete user"); 92 | System.out.println("5. Assign book to user"); 93 | System.out.println("6. Revoke book from user"); 94 | System.out.println("7. Display all users"); 95 | System.out.println("8. Back"); 96 | System.out.print("Select an option: "); 97 | option = sc.nextInt(); 98 | boolean shouldExit = false; 99 | switch (option) { 100 | case 1: 101 | // Create user 102 | usersUtility.createUser(); 103 | break; 104 | case 2: 105 | // Read user 106 | usersUtility.getUser(); 107 | break; 108 | case 3: 109 | // Update user 110 | usersUtility.updateUser(); 111 | break; 112 | case 4: 113 | // Delete user 114 | usersUtility.deleteUser(); 115 | break; 116 | case 5: 117 | // Assign book to user 118 | usersUtility.assignBookToUser(); 119 | break; 120 | case 6: 121 | // Revoke book from user 122 | usersUtility.revokeBookFromUser(); 123 | break; 124 | case 7: 125 | // Display all users 126 | usersUtility.getAllUsers(); 127 | break; 128 | case 8: 129 | shouldExit = true; 130 | break; 131 | default: 132 | // Wrong option 133 | System.out.println("Wrong option!"); 134 | break; 135 | } 136 | System.out.println(); 137 | if (shouldExit) 138 | return; 139 | usersMenu(sc); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/User.java: -------------------------------------------------------------------------------- 1 | public class User { 2 | private String id; 3 | private String name; 4 | private String email; 5 | private String phone; 6 | private String address; 7 | private String currentBooks; 8 | 9 | User(String id, String name, String phone, String email, String address, String currentBooks) { 10 | this.id = id; 11 | this.name = name; 12 | this.phone = phone; 13 | this.email = email; 14 | this.address = address; 15 | this.currentBooks = currentBooks; 16 | } 17 | 18 | public String getId() { 19 | return this.id; 20 | } 21 | 22 | public String getCurrentBooks() { 23 | return this.currentBooks; 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return this.id + ", " + this.name + ", " + this.email + ", " + this.phone + ", " + this.address + ", " 29 | + this.currentBooks; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/UsersUtility.java: -------------------------------------------------------------------------------- 1 | import java.io.BufferedReader; 2 | import java.io.InputStreamReader; 3 | import java.util.ArrayList; 4 | 5 | public class UsersUtility { 6 | private DB db; 7 | private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 8 | 9 | UsersUtility(DB db) { 10 | this.db = db; 11 | } 12 | 13 | public void createUser() { 14 | try { 15 | String name, email, phone, address; 16 | System.out.println("Create new user:"); 17 | System.out.print("Enter name: "); 18 | name = br.readLine(); 19 | System.out.print("Enter email: "); 20 | email = br.readLine(); 21 | System.out.print("Enter phone number: "); 22 | phone = br.readLine(); 23 | System.out.print("Enter address: "); 24 | address = br.readLine(); 25 | User newUser = db.createUser(name, phone, email, address); 26 | System.out.println(newUser.toString()); 27 | } catch (Exception e) { 28 | System.out.println(e); 29 | } 30 | } 31 | 32 | public void getUser() { 33 | try { 34 | String id; 35 | System.out.println("Get user details:"); 36 | System.out.print("Enter user id: "); 37 | id = br.readLine(); 38 | User user = db.readUserByField("id", id); 39 | System.out.println(user.toString()); 40 | } catch (Exception e) { 41 | System.out.println(e); 42 | } 43 | } 44 | 45 | public void updateUser() { 46 | try { 47 | String id, name, phone, email, address; 48 | System.out.println("Update user:"); 49 | System.out.print("Enter user id: "); 50 | id = br.readLine(); 51 | System.out.print("Enter name: "); 52 | name = br.readLine(); 53 | System.out.print("Enter email: "); 54 | email = br.readLine(); 55 | System.out.print("Enter phone number: "); 56 | phone = br.readLine(); 57 | System.out.print("Enter address: "); 58 | address = br.readLine(); 59 | User user = db.updateUser(id, name, phone, email, address); 60 | System.out.println(user.toString()); 61 | } catch (Exception e) { 62 | System.out.println(e); 63 | } 64 | } 65 | 66 | public void deleteUser() { 67 | try { 68 | String id; 69 | System.out.println("Delete user:"); 70 | System.out.print("Enter user id: "); 71 | id = br.readLine(); 72 | db.deleteUser(id); 73 | System.out.println("Deleted user with id: " + id); 74 | } catch (Exception e) { 75 | System.out.println(e); 76 | } 77 | } 78 | 79 | public void getAllUsers() { 80 | try { 81 | System.out.println("All user details:"); 82 | ArrayList users = db.getAllUsers(); 83 | users.forEach((user) -> System.out.println(user.toString())); 84 | } catch (Exception e) { 85 | System.out.println(e); 86 | } 87 | } 88 | 89 | public void assignBookToUser() { 90 | try { 91 | String userId, bookId; 92 | System.out.println("Assign book to user:"); 93 | System.out.print("Enter user id: "); 94 | userId = br.readLine(); 95 | System.out.print("Enter book id: "); 96 | bookId = br.readLine(); 97 | db.assignBookToUser(userId, bookId); 98 | System.out.println("Assigned book to user"); 99 | } catch (Exception e) { 100 | System.out.println(e); 101 | } 102 | } 103 | 104 | public void revokeBookFromUser() { 105 | try { 106 | String userId, bookId; 107 | System.out.println("Revoke book from user:"); 108 | System.out.print("Enter user id: "); 109 | userId = br.readLine(); 110 | System.out.print("Enter book id: "); 111 | bookId = br.readLine(); 112 | db.revokeBookFromUser(userId, bookId); 113 | System.out.println("Revoked book from user"); 114 | } catch (Exception e) { 115 | System.out.println(e); 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/Utils.java: -------------------------------------------------------------------------------- 1 | import java.sql.Connection; 2 | import java.sql.PreparedStatement; 3 | import java.sql.ResultSet; 4 | import java.util.ArrayList; 5 | 6 | public class Utils { 7 | public static void execUpdate(Connection conn, String query) { 8 | try { 9 | PreparedStatement q = conn.prepareStatement(query); 10 | q.executeUpdate(); 11 | } catch (Exception e) { 12 | System.out.println(e); 13 | } 14 | } 15 | 16 | public static ResultSet execQuery(Connection conn, String query) { 17 | try { 18 | PreparedStatement q = conn.prepareStatement(query); 19 | ResultSet res = q.executeQuery(); 20 | return res; 21 | } catch (Exception e) { 22 | System.out.println(e); 23 | return null; 24 | } 25 | } 26 | 27 | public static ArrayList getArrayListFromString(String s) { 28 | ArrayList arr = new ArrayList(); 29 | for (String g : s.split(",")) { 30 | arr.add(g.trim()); 31 | } 32 | return arr; 33 | } 34 | } 35 | --------------------------------------------------------------------------------