Servlet如何连接Oracle
这篇文章给大家分享的是有关Servlet如何连接Oracle的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
把oracle的驱动$ORACL_HOME/jdbc/lib/ojdbc6.jar拷贝到D:\Tomcat5.5.17\webapps\my\WEB-INF\lib。(因为运行时需要该jar包)
package test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
public class Conndb extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
response.setContentType("text/html");
response.setCharacterEncoding("gb2312");
PrintWriter out = response.getWriter();
out.println("
Content: | |
" + rs.getString("ename") + " | ");" + rs.getString("MGR") + " | ");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if(rs != null) {
rs.close();
rs = null;
}
if(stmt != null) {
stmt.close();
stmt= null;
}
if(conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
感谢各位的阅读!关于"Servlet如何连接Oracle"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!