package com.zking.util;
import java.net.ConnectException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import oracle.jdbc.driver.OracleDriver;
public class DBHerpl {
private static final String URL="jdbc:oracle:thin:@localhost:1521:orcl";
private static final String CLASS_NAME="oracle.jdbc.driver.OracleDriver";
static {
try {
Class.forName(CLASS_NAME);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void closeObj(Connection con,PreparedStatement ps,ResultSet rs) {
try {
if(con!=null && !con.isClosed()) {
con.close();
}if(ps!=null) {
ps.close();
}if(rs!=null) {
rs.close();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getCon() {
Connection con=null;
try {
con=DriverManager.getConnection(URL, "scott", "tiger");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return con;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>js_01</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!-- 配置servlet -->
<!-- DemoServlet -->
<servlet>
<servlet-name>registerServlet</servlet-name>
<servlet-class>com.zking.demo.RegisterServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>registerServlet</servlet-name>
<!-- 设置servlet的映射路径 -->
<url-pattern>/registerServlet.do</url-pattern>
</servlet-mapping>
</web-app>