· 8 years ago · Dec 09, 2017, 07:10 AM
1package com.example.myapplication.data;
2
3import java.io.Serializable;
4import java.sql.Connection;
5import java.sql.DriverManager;
6import java.sql.SQLException;
7import java.sql.Statement;
8import java.util.Random;
9
10import com.vaadin.data.util.BeanItemContainer;
11
12@SuppressWarnings("serial")
13public class SubscriberContainer<subscriber_id> extends BeanItemContainer<Subscriber> implements Serializable{
14
15 /**
16 * Natural property order for Person bean. Used in tables and forms.
17 */
18 public static final Object[] NATURAL_COL_ORDER = new Object[] {
19 "subscriber_id", "phone_number", "customer_id", "account_number", "account_name",
20 "wallet_number"};
21
22 /**
23 * "Human readable" captions for properties in same order as in
24 * NATURAL_COL_ORDER.
25 */
26 public static final String[] COL_HEADERS_ENGLISH = new String[] {
27 "subscriber_id", "phone_number", "customer_id", "account_number", "account_name",
28 "wallet_number"};
29
30 public SubscriberContainer() throws InstantiationException,IllegalAccessException {
31 super(Subscriber.class);
32 }
33
34 private void initConnectionPool() {
35 try {
36 connectionPool = new SimpleJDBCConnectionPool(
37 "com.mysql.jdbc.Driver ",
38 " jdbc:mysql://localhost:3306/juk_app", "root", "");
39 } catch (SQLException e) {
40 showError("Couldn't create the connection pool!");
41 e.printStackTrace();
42 }
43 }
44
45 private void initDatabase() {
46 try {
47 Connection con = DriverManager.getConnection(url,"root", "");
48 Statement statement = conn.createStatement();
49 try {
50 statement.executeQuery("SELECT * FROM subscribers");
51 } catch (SQLException e) {
52 // Failed, which means that we should init the database
53 Statement.executeUpdate
54 DROP TABLE IF EXISTS subscribers;
55 CREATE TABLE subscribers
56 (subscriber_id int(15) UNSIGNED NOT NULL AUTO_INCREMENT,
57 phone_number varchar(20) NOT NULL ,
58 customer_id varchar(15) ,
59 account_number varchar(15) NOT NULL,
60 account_name varchar(35),
61 wallet_number varchar(20) ,
62 PRIMARY KEY(subscriber_id),
63 UNIQUE (subscriber_id);
64 UNIQUE(phone_number) ;
65 con.close();
66 }catch( Exception e ) {
67 e.printStackTrace();
68 }}