JDBC API Usage: Difference between revisions
Jump to navigation
Jump to search
(→Query) |
(→Query) |
||
Line 18: | Line 18: | ||
=Query= | =Query= | ||
<syntaxhighlight lang=' | <syntaxhighlight lang='java'> | ||
... | ... | ||
private DataSource dataSource; | private DataSource dataSource; | ||
Line 25: | Line 25: | ||
Connection c; | Connection c; | ||
try { | try { | ||
Revision as of 19:43, 26 September 2017
Internal
JDBC Connection Life Cycle
Database Metadata
The database metadata is an object that contains metadata about the database the current connection belongs to.
Connection c = ...;
DatabaseMetaData dmd = c.getMetaData();
Query
...
private DataSource dataSource;
...
Connection c;
try {
c = dataSource.getConnection();
PreparedStatement s = c.prepareStatement("SELECT * FROM SOME_TABLE");
ResultSet rs = s.executeQuery();
while(rs.next()) {
//
// columns are 1-based
//
String column1Value = rs.getString(1);
Long column2Value = rs.getLong(2);
...
}
}
finally {
c.close();
}