Добавлено: 17 фев 2005, 16:17
Deady, Чего-то не получается ничего.... пустая страница и все....
Код: Выделить всё
<%@ page import="java.sql.*"%>
<% Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@220.220.220.220:1111:orc", "hr","hr");
conn.setAutoCommit (false);
st = conn.createStatement();
rs = st.executeQuery("SELECT id, name FROM test ORDER BY name");
%>
<table>
<%
while (rs.next()) {
int id = rs.getInt(1);
String name = rs.getString(2); if (name!=null) name = name.trim();
%>
<tr>
<td><%= id %></td>
<td><%= name %></td>
</tr>
<%
}
%>
</table>
<%
rs.close();
rs = null;
st.close();
st = null;
conn.close();
conn = null;
}
catch (Exception e) {
e.printStackTrace;
out.print(e);
}
finally {
if (rs!= null)
try {
rs.close();
rs = null;
} catch (Exception e) {
e.printStackTrace();
out.print(e);
}
if (st!= null)
try {
st.close();
st = null;
} catch (Exception e) {
e.printStackTrace();
out.print(e);
}
if (conn!= null)
try {
conn.close();
conn = null;
} catch (Exception e) {
e.printStackTrace();
out.print(e);
}
}//finally
%>