日期:2014-05-18  浏览次数:20847 次

贼奇怪的一个巨大问题!!
jdbc   odbc   在命令行下连接数据库成功  

在jsp页面下连接不成功!   我郁闷  
我直接发源代码.  


命令行下  
import   java.sql.*;  
public   class   Shell  
{  
public   static   void   main(String[]   args)  
{  
String   sql;  
Connection   conn;  
Statement   stmt;  
ResultSet   rs;  
try  
{  
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();  
String   url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=university ";  
String   user= "sa ";  
String   password= " ";  
conn=   DriverManager.getConnection(url,user,password);  
stmt=conn.createStatement();  
sql= "select   *   from   Student ";  
rs=stmt.executeQuery(sql);  
while(rs.next())  
{  
System.out.println(rs.getString(1));  
System.out.println(rs.getString(2));  
}  
rs.close();  
stmt.close();  
conn.close();  
}  
catch(Exception   e)  
{  
e.printStackTrace();  
}  
}  
}  


页面下!!  
<%@   page   language= "java "   import= "java.util.* "   import= "java.sql.* "   pageEncoding= "GBK "%>  
<%  
String   path   =   request.getContextPath();  
String   basePath   =   request.getScheme()+ ":// "+request.getServerName()+ ": "+request.getServerPort()+path+ "/ ";  
%>  

<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN ">  
<html>  
<head>  
<base   href= " <%=basePath%> ">  

<title> My   JSP   'sql.jsp '   starting   page </title>  

<meta   http-equiv= "pragma "   content= "no-cache ">  
<meta   http-equiv= "cache-control "   content= "no-cache ">  
<meta   http-equiv= "expires "   content= "0 ">  
<meta   http-equiv= "keywords "   content= "keyword1,keyword2,keyword3 ">  
<meta   http-equiv= "description "   content= "This   is   my   page ">  
<!--  
<link   rel= "stylesheet "   type= "text/css "   href= "styles.css ">  
-->  

</head>  

<body>  
<%  
String   sql;  
Connection   conn;  
Statement   stmt;  
ResultSet   rs;  
try  
{  
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();  
String   url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=university ";  
String   user= "sa ";  
String   password= " ";  
conn=   DriverManager.getConnection(url,user,password);  
stmt=conn.createStatement();  
sql= &quo