高位高手:
实际是能连接数据库的 但ConnectDb.ConnectDb() 值 始终是null
请指点!
package ConnectDataBase;
import java.sql.*;
public class ConnectDb {
public static Connection con;
public static Connection ConnectDb(){
String driverName = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
String dbURL = "jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=pubs";
String userName = "sa";
String userPwd = "";
Connection dbConn = null;
try
{
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!");
}
catch (Exception e)
{
System.out.println("Connection error!");
e.printStackTrace();
}
return dbConn;
}
}
<%@ page import="ConnectDataBase.ConnectDb" %>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
if (ConnectDb.ConnectDb()!=null)
{out.println("连接数据库成功!");}
else
{out.println("连接数据库error!");}
%>
显示连接数据库error!实际是能连接数据库的 但ConnectDb.ConnectDb() 值 始终是null