我装VS,里面带了个 SQL SERVER 2005 EXPRESS 版的,查了很多网上文章.
也试了下,用JAVA程序可以连接到数据库.但是用到JSP网页里就是不行.
已经下过了 JDBC 驱动包,放在 common /lib 和 root /web-inf/lib 目录下
root,是我放网页的地方.
已经配置过SQL EXPRESS,开启了TCP/IP,端口 1433.
下面是连接的部分代码:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://emote;" +
"databaseName=jsp;integratedSecurity=true;user=sa;password=12345;";
Connection conn = DriverManager.getConnection(connectionUrl);
if(conn==null){
System.out.println("Connect Error<br>");
}else{out.println("Connect OK!<br>");}下面是出错的提示.
javax.servlet.ServletException: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused: connect
也试了下,用JAVA程序可以连接到数据库.但是用到JSP网页里就是不行.
已经下过了 JDBC 驱动包,放在 common /lib 和 root /web-inf/lib 目录下
root,是我放网页的地方.
已经配置过SQL EXPRESS,开启了TCP/IP,端口 1433.
下面是连接的部分代码:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://emote;" +
"databaseName=jsp;integratedSecurity=true;user=sa;password=12345;";
Connection conn = DriverManager.getConnection(connectionUrl);
if(conn==null){
System.out.println("Connect Error<br>");
}else{out.println("Connect OK!<br>");}下面是出错的提示.
javax.servlet.ServletException: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION ** java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused: connect
Connection con=DriverManager.getConnection(url,username,password);
三个参数啊?url写:协议+地址+端口号+数据库名。
再看看是不是这里错了,至于你的这个重载方法我没用过,不熟悉。另外驱动jar包放在/WEB-INF/lib下就可以,不用数据源不用放在common/lib。还有WEB-INF要大写,没有写错吧?既然报的是socket的Exception,那么类加载(Class.forName())应该是成功了,主要问题我想是出来取得连接上了。
http://www.86oo.com/html/113/12563.html