Package ch.k43.util
Klasse KDB
java.lang.Object
ch.k43.util.KDB
- Alle implementierten Schnittstellen:
AutoCloseable
Database class to support compliant JDBC databases.
Example:
try (KDB db = new KDB(KDB.JDBC_H2, "jdbc:h2:mem:mydb", "", "")) { KLog.abort(!db.isConnected(), "Error: " + db.getErrorMessage()); db.exec("CREATE TABLE ADDRESSES (SEQUENCE INT AUTO_INCREMENT, LASTNAME VARCHAR(20), FIRSTNAME VARCHAR(20))"); db.prepare("INSERT INTO ADDRESSES (LASTNAME, FIRSTNAME) VALUES (?, ?)"); db.execPrepare("Smith", "Joe"); db.execPrepare("Miller", "Bob"); db.execPrepare("Johnson", "Evelyn"); db.exec("SELECT * FROM ADDRESSES"); System.out.println(db.getDataAsTable()); }
- Seit:
- 2024.06.14
-
Feldübersicht
Modifizierer und TypFeldBeschreibungstatic final String
Cloudscape JDBC driverstatic final String
DB2 JDBC driverstatic final String
Derby driversstatic final String
H2 JDBC driverstatic final String
HSQLDB JDBC driverstatic final String
Informix JDBC driverstatic final String
MariaDB JDBC driverstatic final String
MS SQL JDBC driverstatic final String
MySQL JDBC driverstatic final String
Oracle JDBC driverstatic final String
PostGreSQL JDBC driverstatic final String
SQLite JDBC driverstatic final String
Sybase JDBC driver -
Konstruktorübersicht
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoid
close()
Close the JDBC connection.boolean
commit()
Commit transaction.boolean
Execute dynamic SQL statement.boolean
Execute dynamic SQL statement.boolean
Execute dynamic SQL statement.boolean
execPrepare
(Object... argObjects) Complete and execute precompiled SQL statement.int
Get number of columns in result set.String[]
Get column names in result set.int[]
Get column widths in result set.getData()
Get fetched data as an ArrayList (rows) with an array of Objects (columns).Get result set formatted as CSV string.getDataAsCSV
(char argDelimiter) Get result set formatted as CSV string.getDataAsCSV
(char argDelimiter, boolean argHeader) Get result set formatted as CSV string delimited by the passed character (Example: ',')Get result set formatted as JSON stringGet result set formatted as display table with column headersgetDataAsTable
(boolean argHeader) Get result set formatted as display tableGet result set formatted as XML UTF-8 stringGet result set formatted as YAML stringlong
Get elapsed time of last SQL statement.Get last error message.long
Get number of rows read or updated.Get table name of first column of result set.getTableName
(int argColumnNumber) Get table name of given column number.boolean
Get state of JDBC connection.boolean
Prepare SQL statement.boolean
Prepare SQL statement.boolean
Prepare SQL statement.boolean
rollback()
Rollback transaction.void
setAutoCommit
(boolean argState) Set auto commit state.toString()
String representation of object.
-
Felddetails
-
JDBC_ORACLE
Oracle JDBC driver- Siehe auch:
-
JDBC_MYSQL
MySQL JDBC driver- Siehe auch:
-
JDBC_H2
H2 JDBC driver- Siehe auch:
-
JDBC_DB2
DB2 JDBC driver- Siehe auch:
-
JDBC_POSTGRESQL
PostGreSQL JDBC driver- Siehe auch:
-
JDBC_MSSQL
MS SQL JDBC driver- Siehe auch:
-
JDBC_SYBASE
Sybase JDBC driver- Siehe auch:
-
JDBC_CLOUDSCAPE
Cloudscape JDBC driver- Siehe auch:
-
JDBC_INFORMIX
Informix JDBC driver- Siehe auch:
-
JDBC_HSQLDB
HSQLDB JDBC driver- Siehe auch:
-
JDBC_DERBY
Derby drivers- Siehe auch:
-
JDBC_SQLITE
SQLite JDBC driver- Siehe auch:
-
JDBC_MARIADB
MariaDB JDBC driver- Siehe auch:
-
-
Konstruktordetails
-
KDB
Load JDBC driver and establish connection to database.- Parameter:
argDriverClass
- JDBC driver class name (Example: "org.h2.Driver")argURL
- JDBC connection URL (Example: "jdbc:h2:mem:myDb")argUserName
- User nameargPassword
- Password
-
-
Methodendetails
-
close
public void close()Close the JDBC connection.- Angegeben von:
close
in SchnittstelleAutoCloseable
-
commit
public boolean commit()Commit transaction.- Gibt zurück:
- True if successful, false otherwise
- Seit:
- 2024.06.17
-
exec
Execute dynamic SQL statement. For SELECT statements, the result set is fetched and saved as convenient Java Objects to be retrieved by getDataXXX().- Parameter:
argStatement
- SQL statement- Gibt zurück:
- Success or failure
-
exec
Execute dynamic SQL statement. For SELECT statements, the result set is fetched and saved as convenient Java Objects to be retrieved by getDataXXX().- Parameter:
argStatement
- SQL statementargMaxRows
- Maximum number of rows to fetch or 0 for all- Gibt zurück:
- Success or failure
- Seit:
- 2024.08.19
-
exec
Execute dynamic SQL statement. For SELECT statements, the result set is fetched and saved as convenient Java Objects to be retrieved by getDataXXX().- Parameter:
argStatement
- SQL statementargMaxRows
- Maximum number of rows to fetch or 0 for allargTimeOutSec
- Execution time out in seconds or 0 for no timeout- Gibt zurück:
- Success or failure
- Seit:
- 2024.09.17
-
execPrepare
Complete and execute precompiled SQL statement. For SELECT statements, the result set is fetched and saved as convenient Java Objects to be retrieved by getDataXXX().- Parameter:
argObjects
- ... Values to be inserted in the sequence of the placeholder(s) '?' of the precompiled SQL statement- Gibt zurück:
- Success or failure
- Seit:
- 2024.10.23
-
getColumnCount
public int getColumnCount()Get number of columns in result set.- Gibt zurück:
- Number of columns or 0
-
getColumnNames
Get column names in result set.- Gibt zurück:
- Column names or null
-
getColumnWidths
public int[] getColumnWidths()Get column widths in result set.- Gibt zurück:
- Column width or null
-
getData
Get fetched data as an ArrayList (rows) with an array of Objects (columns).- Gibt zurück:
- Array with data or null
-
getDataAsCSV
Get result set formatted as CSV string. The default field delimiter is a comma.- Gibt zurück:
- CSV string or null
-
getDataAsCSV
Get result set formatted as CSV string.- Parameter:
argDelimiter
- Delimiter character- Gibt zurück:
- CSV string or null
-
getDataAsCSV
Get result set formatted as CSV string delimited by the passed character (Example: ',')- Parameter:
argDelimiter
- Delimiter characterargHeader
- Write header line with column names- Gibt zurück:
- CSV string or null
- Seit:
- 2024.06.21
-
getDataAsJSON
Get result set formatted as JSON string- Gibt zurück:
- JSON string or null
-
getDataAsTable
Get result set formatted as display table with column headers- Gibt zurück:
- String with formatted table
-
getDataAsTable
Get result set formatted as display table- Parameter:
argHeader
- True to add column header, false otherwise- Gibt zurück:
- String with formatted table
- Seit:
- 2024.09.01
-
getDataAsXML
Get result set formatted as XML UTF-8 string- Gibt zurück:
- XML string or null
-
getDataAsYAML
Get result set formatted as YAML string- Gibt zurück:
- YAML string or null
- Seit:
- 2024.09.14
-
getElapsedTime
public long getElapsedTime()Get elapsed time of last SQL statement.- Gibt zurück:
- Elapsed time in milliseconds or 0
- Seit:
- 2024.06.24
-
getErrorMessage
Get last error message.- Gibt zurück:
- Error message or null
-
getRowCount
public long getRowCount()Get number of rows read or updated.- Gibt zurück:
- Row count
-
getTableName
Get table name of first column of result set. Note: The underlying JDBC call does not always return the table name, as in SELECT COUNT(*).- Gibt zurück:
- Table name or null
-
getTableName
Get table name of given column number. Note: The underlying JDBC call does not always return the table name, as in SELECT COUNT(*).- Parameter:
argColumnNumber
- Column number for which the table name is returned- Gibt zurück:
- Table name or null
- Seit:
- 2024.06.27
-
isConnected
public boolean isConnected()Get state of JDBC connection.- Gibt zurück:
- True if connected, false otherwise
-
prepare
Prepare SQL statement. The prepared statement must later be executed withexecPrepared()
.- Parameter:
argStatement
- SQL statement- Gibt zurück:
- Success or failure
- Seit:
- 2024.09.25
-
prepare
Prepare SQL statement. The prepared statement must later be executed withexecPrepare()
.- Parameter:
argStatement
- SQL statementargMaxRows
- Maximum number of rows to fetch or 0 for allargTimeOutSec
- Execution time out in seconds or 0 for no time out- Gibt zurück:
- Success or failure
- Seit:
- 2024.10.24
-
prepare
Prepare SQL statement. The prepared statement must later be executed withexecPrepared()
.- Parameter:
argStatement
- SQL statementargMaxRows
- Maximum number of rows to fetch or 0 for all- Gibt zurück:
- Success or failure
- Seit:
- 2024.09.25
-
rollback
public boolean rollback()Rollback transaction.- Gibt zurück:
- True if successful, false otherwise
- Seit:
- 2024.06.17
-
setAutoCommit
public void setAutoCommit(boolean argState) Set auto commit state.- Parameter:
argState
- True for auto commit, false otherwise- Seit:
- 2024.06.26
-
toString
String representation of object.
-