[英]how to increase the data transfer speed from oracle 10g into jsp pages using scriplet
[英]How to retrieve data from 10g in java servlet & JSP
在Servlet和JSP中從數據庫10g檢索數據
有很多方法可以給這只貓剝皮。
一個取決於您使用的Web框架(如果有)。 就個人而言,無論您選擇哪種Web框架,我都是使用Spring的忠實粉絲。 它使很多事情變得容易得多。 輕量級的持久性框架包括Spring JDBC和我最喜歡的Ibatis 。
實際上,我編寫了有關使用Spring和Ibatis的教程 。 實際上,它甚至使用Oracle 10g Express Edition (“ Oracle XE”)。
使用(訂購是我的偏愛)
除非您只有一堆額外的時間,否則請不要使用直接JDBC。
其他答案也列出了為實現這一目標而應該追求的最佳技術。 但是要直接回答這個問題,也許最直接的答案是一個簡單的舊JDBC示例:
private void getYourData() {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rset = null;
try {
Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:/comp/env");
DataSource ds = (DataSource) envContext.lookup("jdbc/yourDatabase");
conn = ds.getConnection();
pstmt = conn.prepareStatement(
"select yourdata " +
" from yourtable " +
" where yourkey = ? "
);
pstmt.setInt(1, yourKeyValue);
rset = pstmt.executeQuery();
while (rset.next()) {
String yourData = rset.getString("yourdata");
}
conn.commit();
} catch (NamingException ne) {
log.error(ne.getMessage());
} catch (SQLException se) {
log.error(se.getMessage());
} finally {
if (rset != null) {
try {
rset.close();
} catch (Exception e) {
log.error(e.getMessage());
}
}
if (pstmt != null) {
try {
pstmt.close();
} catch (Exception e) {
log.error(e.getMessage());
}
}
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
log.error(e.getMessage());
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.