主题:在Servlet中连接数据库的问题
如下这个程序有一些 错误,请你找出来并改正,并说明原因,非常感谢。
public class TestServlet extends HttpServlet{
private final static String drv = "oracle.jdbc.driver.OracleDriver";
private final static String url="jdbc:oracle:thin@210.220.251.96:1521:ORA8i";
private final static String uer="user";
private final static password="123";
private ServletContext context;
private Connection conn=null;
private Statement stmt=null;
private ResultSet rs=null;
public void init(ServletConfig config) throws ServletException{
super.init(config);
context = config.getServletContext();
try{
Class.forName(drv);
}catch(ClassNotFoundException e){
throw new ServletException(e.getStackTrace());
}
}
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException,SQLException
{
String id=req.getParameter("id");
conn = DriverManager.getConnection(url,user,password);
stmt=conn.createStatement();
rs=stmt.executeQuery("select....where id='"+id+"'");
while(rs.next()){
...
}
rs.close();
stmt.close();
conn.close();
...
}
}
public class TestServlet extends HttpServlet{
private final static String drv = "oracle.jdbc.driver.OracleDriver";
private final static String url="jdbc:oracle:thin@210.220.251.96:1521:ORA8i";
private final static String uer="user";
private final static password="123";
private ServletContext context;
private Connection conn=null;
private Statement stmt=null;
private ResultSet rs=null;
public void init(ServletConfig config) throws ServletException{
super.init(config);
context = config.getServletContext();
try{
Class.forName(drv);
}catch(ClassNotFoundException e){
throw new ServletException(e.getStackTrace());
}
}
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException,SQLException
{
String id=req.getParameter("id");
conn = DriverManager.getConnection(url,user,password);
stmt=conn.createStatement();
rs=stmt.executeQuery("select....where id='"+id+"'");
while(rs.next()){
...
}
rs.close();
stmt.close();
conn.close();
...
}
}