Databases Flashcards

1
Q

jdbc url
+ oracle thin
+ derby

A

jdbc:provider:driverType:connectionDetails
jdbc:oracle:thin:@host:port:dbName
jdbc:derby:host:port:dbName

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Obyc. update statement
Syntax od zacatku do konce

A

Connection conn = DriverManager.getConnection(url, user, pass);
Statement s = conn.createStatement(“update …”);
int updatedRows = s.executeUpdate();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Tvorba prepared statementu se 2 String parametry - dva zpusoby setovani.

A

PreparedStatement ps = conn.prepareStatement(“select … ?”);
ps.setObject(1, “value”, Types.VARCHAR);
ps.setString(2, “value);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Tvorba callable statementu s in i out parametrem numerickym

A

CallableStatement cs = conn.prepareCall(“? = function(?)”);
cs.registerOutParameter(1, Types.NUMERIC);
cs.setBigDecimal(2, value)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

metody vykonani statementu (3)
+ jak jinak ziskat vysledek a pocet zmenenych radku (2)

A

ResultSet rs = st.executeQuery();
int rows = st.executeUpdate();
boolean isSelect = st.execute();

st.getResultSet()
st.getUpdateCount()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Auto-commit chovani
+ jak ho zjistit a ovlivnit

A

Default: auto-commit po exekuci statementu
conn.getAutoCommit()
conn.setAutoCommit(false)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

metody ridici transakce (2,5)

A

conn.commit()
conn.rollback()
Savepoint sp = conn.setSavepoint()
conn.rollback(sp)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Zavirani jdbc

A

Nutne vzdy!
try with resources
nebo finally

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

ResultSet - typy (3)
pohyby (6)

A

ResultSet.TYPE_FORWARD_ONLY - jen next()
ResultSet.TYPE_SCROLL_INSENSITIVE - zmeny se neprojevi
ResultSet.TYPE_SCROLL_SENSITIVE
next(), previous(), first(), last(), absolute(rowNumber), relative(rows)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

ResultSet - concurrency (2)

A

= updatovatelnost
ResultSet.CONCUR_READ_ONLY
ResultSet.CONCUR_UPDATABLE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

ResultSet - holdability (2)

A

= dostupnost dat po commitu
ResultSet.HOLD_CURSOR_OVER_COMMIT
ResultSet.CLOSE_CURSOR_AT_COMMIT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

ResultSet - jak ziskat pocet sloupcu, jmeno a typ 1. sloupce

A

ResultSetMetaData rsmd = ResultSet.getMetaData()
rsmd.getColumnCount()
rsmd.getColumnName(1)
rsmd.getColumnType(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Databazova vyjimka - typ a dve metody vlastnosti

A

SQLException
e.getErrorCode
e.getSQLStatus

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Ziskani date hodnoty z ResultSet (2)

A

if (rs.next()) {
Date x = rs.getObject(1, Date.class);
// Date x = rs.getDate(1);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Jak zjistit, jestli db podporuje outer join nebo savepoint?

A

DatabaseMetaData dbmd = conn.getDatabaseMetaData();
dbmd.supportsOuterJoins()
dbmd.supportsSavepoints()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Jak zjistit, jestli result set podporuje konkretni typ, concurrency a holdability?

A

database metadata:
supportsResultSetType(x)
supportsResultSetConcurrency(x)
supportsResultSetHoldability(x)

17
Q

Jak vypsat klicova slova podporovana databazi, verzi a jmeno db?

A

database metadata:
getSQLKeywords
getDatabaseProductVersion
getDatabaseProductName