参考以下:
java web项目测试用Web的测试工具,如HtmlUnit,JWebUnit等。
main()方法就可以测试,在main方法中获得connection对象将他输出就可以了。
如果正常输出一大串就是对了。
例子:
public class DBConnection {
private static String url = "jdbc:sqlserver://localhost:1433;DataBaseName=HXParserDB";
private static String username = "sa";
private static String password = "123";
private DBConnection(){}
private static DBConnection dbconn = new DBConnection();
private static Connection conn = null;
// 注册驱动
static {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
}
}
public DBConnection getDBConn(){
if(null==dbconn){
dbconn = new DBConnection();
}
return dbconn;
}
// 返回Connection对象
public static Connection getConnection() {
try {
return DriverManager.getConnection(url, username, password);
} catch (SQLException e) {
return null;
}
}
/**
* @param args
*/
public static void main(String[] args) {
System.out.println(DBConnection.getConnection());
}
}