日期:2014-05-16 浏览次数:20468 次
#driverClass(数据库驱动类的类名) #driverClass=oracle.jdbc.OracleDriver driverClass=com.mysql.jdbc.Driver #url(要连接数据库的地址) #url=jdbc:oracle:thin:@192.168.1.180:1521:orcl #url=jdbc:mysql://127.0.0.1:3306/test url=jdbc:mysql://127.0.0.1:3306 #user(数据库用户) #user=scott user=root #password(密码) #password=tiger password=root
<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0" metadata-complete="true"> <context-param> <param-name>driverClass</param-name> <param-value>com.mysql.jdbc.Driver</param-value> </context-param> <context-param> <param-name>url</param-name> <param-value>jdbc:mysql://localhost:3306/test</param-value> </context-param> <context-param> <param-name>user</param-name> <param-value>root</param-value> </context-param> <context-param> <param-name>password</param-name> <param-value>root</param-value> </context-param> <servlet> <servlet-name>ConnDBServlet</servlet-name> <servlet-class>conntest.ConnDBServlet</servlet-class> <init-param> <param-name>driverClass</param-name> <param-value>com.mysql.jdbc.Driver</param-value> </init-param> <init-param> <param-name>url</param-name> <param-value>jdbc:mysql://localhost:3306</param-value> </init-param> <init-param> <param-name>user</param-name> <param-value>root</param-value> </init-param> <init-param> <param-name>password</param-name> <param-value>root</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>ConnDBServlet</servlet-name> <url-pattern>/conndb</url-pattern> </servlet-mapping> </web-app>
package conntest; public class DBConfig{ private String driverClass; private String url; private String user; private String password; public DBConfig(String driverClass, String url, String user, String password){ this.driverClass = driverClass; this.url = url; this.user = user; this.password = password; } public String getDriverClass(){ return this.driverClass; } public String getUrl(){ return this.url; } public String getUser(){