Java Reference
In-Depth Information
System.err.println("SQL
error
:
"+sqlex.getMessage());
System.err.println("SQL
state
:
"+sqlex.getSQLState());
System.err.println("Error
code:
"+sqlex.getErrorCode());
System.err.println("Cause:
"+sqlex.getCause());
sqlex = sqlex.getNextException();
}
}
}
static void dump(ResultSet rs) throws SQLException
{
while (rs.next())
System.out.println(rs.getInt("ID")+"
"+rs.getString("NAME")+
" "+rs.getBoolean("FIRED"));
System.out.println();
}
public static void fire(int id) throws SQLException
{
Connection
con
=
DriverMan-
ager.getConnection("jdbc:default:connection");
String sql = "UPDATE EMPLOYEES SET FIRED=TRUE WHERE
ID="+id;
try (Statement stmt = con.createStatement())
{
stmt.executeUpdate(sql);
}
}
}
MuchofthislistingshouldbefairlyunderstandablesoI'llonlydiscussthe fire()
method.Aspreviouslystated,thismethodisinvokedasaresultofthecallablestatement
invocation.
Search WWH ::




Custom Search