JDBC Driver 放在WEB-INF 的lib包中
private String username="root";
private String password="root";
private Connection connection = null;
private Statement statement = null;
private ResultSet resultSet=null;
private String url;
public void init(String dbname, String username, String password) {
// TODO Auto-generated method stub
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/"+dbname, username,password);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
这是mysql的模板 你自己改成你需要的数据库就行了
取消
评论