public class DerbyConnection extends Object implements DBConnectionStrategy
Constructor and Description |
---|
DerbyConnection() |
Modifier and Type | Method and Description |
---|---|
int |
countRows(String tableName)
counts the rows of a given table
|
int[] |
countsRowsAndCols(String tableName)
counts rows and columns of a give database table
|
void |
createConnection(String url,
String user,
String pass)
creates a connection to a database driver
|
void |
createTable(String tableName,
Cell[][] cells)
creates a new table in the database
|
void |
deleteRows(String tableName,
String[] toDelete)
deletes rows from a database table
|
void |
disconnet()
closes connection from the database
|
String[][] |
getTableContent(String tableName)
returns the data of a given table
|
String[] |
getTableList(ArrayList list)
returns all the tables availabe int he database
|
void |
insertNewData(String tableName,
String[][] newData)
inserts a new row into a database table
|
String[][] |
queryTo2dArray(ArrayList array,
String[][] table)
converts database table-content stored in an array list to a 2D String array
|
ArrayList |
queryToArray()
saves the result of a SQL expression into an arraylist
|
ArrayList |
queryToArray(String tableName)
saves a SQL query in an ArrayList
|
void |
updateRow(String tableName,
String column,
String origin,
String destination)
updates a single row in a database table
|
void |
updateTable()
updates a given table
|
public DerbyConnection()
public void createConnection(String url, String user, String pass) throws ClassNotFoundException, SQLException
DBConnectionStrategy
createConnection
in interface DBConnectionStrategy
url
- path to driveruser
- usernamepass
- passwordClassNotFoundException
SQLException
public void createTable(String tableName, Cell[][] cells)
DBConnectionStrategy
createTable
in interface DBConnectionStrategy
tableName
- table's namecells
- cells to be added to the tablepublic void disconnet()
DBConnectionStrategy
disconnet
in interface DBConnectionStrategy
public ArrayList queryToArray()
DBConnectionStrategy
queryToArray
in interface DBConnectionStrategy
public String[] getTableList(ArrayList list)
DBConnectionStrategy
getTableList
in interface DBConnectionStrategy
public String[][] getTableContent(String tableName)
DBConnectionStrategy
getTableContent
in interface DBConnectionStrategy
public void updateTable()
DBConnectionStrategy
updateTable
in interface DBConnectionStrategy
public ArrayList queryToArray(String tableName) throws SQLException
DBConnectionStrategy
queryToArray
in interface DBConnectionStrategy
SQLException
public int[] countsRowsAndCols(String tableName) throws SQLException
DBConnectionStrategy
countsRowsAndCols
in interface DBConnectionStrategy
tableName
- table nameSQLException
public int countRows(String tableName) throws SQLException
DBConnectionStrategy
countRows
in interface DBConnectionStrategy
SQLException
public String[][] queryTo2dArray(ArrayList array, String[][] table)
DBConnectionStrategy
queryTo2dArray
in interface DBConnectionStrategy
array
- arralist with table-contenttable
- 2D arraypublic void updateRow(String tableName, String column, String origin, String destination)
DBConnectionStrategy
updateRow
in interface DBConnectionStrategy
tableName
- table's namecolumn
- table's columnorigin
- value to be finaldestination
- primary key in databasepublic void insertNewData(String tableName, String[][] newData)
DBConnectionStrategy
insertNewData
in interface DBConnectionStrategy
tableName
- database table namenewData
- 2D array with data to be added to the databasepublic void deleteRows(String tableName, String[] toDelete)
DBConnectionStrategy
deleteRows
in interface DBConnectionStrategy
tableName
- database table nametoDelete
- array with primary keys for deletion