Content deleted Content added
No edit summary |
mNo edit summary |
||
Line 139:
"jdbc:somejdbcvendor:other data needed by some jdbc vendor",
"myLogin",
"myPassword"
/* you use the connection here */
} // the VM will take care of closing the connection
Line 148:
<source lang=java5>
try (Statement stmt = conn.createStatement()) {
stmt.executeUpdate(
}
</source>
Line 163:
ResultSet rs = stmt.executeQuery( "SELECT * FROM MyTable" )
) {
while (
int numColumns = rs.getMetaData().getColumnCount();
for (
// Column numbers start at 1.
// Also there are many methods on the result set to return
// the column as a particular type. Refer to the Sun documentation
// for the list of valid conversions.
System.out.println( "COLUMN " + i + " = " + rs.getObject(i)
}
}
Line 180:
<source lang=java5>
try (PreparedStatement ps =
conn.prepareStatement(
) {
// In the SQL statement being prepared, each question mark is a placeholder
// that must be replaced with a value you provide through a "set" method invocation.
Line 194:
// positioned before the first row.
try (ResultSet rs = ps.executeQuery()) {
while (
int numColumns = rs.getMetaData().getColumnCount();
for (
// Column numbers start at 1.
// Also there are many methods on the result set to return
// the column as a particular type. Refer to the Sun documentation
// for the list of valid conversions.
System.out.println(
} // for
} // while
Line 241:
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(URL, "
Statement stmt = conn.createStatement();
String sql = "INSERT INTO emp1 VALUES ('
stmt.executeUpdate(sql);
|