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

jsp连接sql2000 顽疾 在线等!!!!!
<%Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");  
String   url= "jdbc:sqlserver://localhost:1433;DatabaseName=Student ";  
//student为你的数据库的  
String   user= "henson ";        
String   password= "123 ";  
  Connection   conn=   DriverManager.getConnection(url,user,password);  
Statement   stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);  
String   sql= "select   *   from   student ";  
ResultSet   rs=stmt.executeQuery(sql);  
while(rs.next())   {%>  
  您的第一个字段内容为: <%=rs.getString(1)%>  
  您的第二个字段内容为: <%=rs.getString(2)%>  
   <%}%>  
   <%out.print( "数据库操作成功,恭喜你 ");%>  
   <%rs.close();  
          stmt.close();  
          conn.close();
%>  
用这个可以连接数据库输出数据,打了补丁sp3,放好了驱动文件在tomcat/common/lib中
package   student;
import   java.sql.*;
public   class   conn   {
String   sDBDriver= "sun.jdbc.odbc.JdbcOdbcDriver ";
String   sConnStr= "jdbc:odbc:student ";
Connection   conn=null;    
ResultSet   rs=null;

public   conn(){
try{
Class.forName(sDBDriver);  
}catch(java.lang.ClassNotFoundException   e){
System.err.println(e.getMessage());
}
}
public   ResultSet   executeQuery(String   sql){
try{
conn=DriverManager.getConnection(sConnStr);
Statement   stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}catch(SQLException   ex){
System.err.println(ex.getMessage());
}
return   rs;
}
}
这个可以连接到数据源,没有出现提示:[Microsoft][ODBC   驱动程序管理器]   未发现数据源名称并且未指定默认驱动程序
究竟是什么问题呢?   在线等

最后一个Bebug:  
Thread   [http-8080-1]   (Suspended   (exception   NullPointerException))
ErrorDispatcher.createJavacError(String,   Node$Nodes,   StringBuffer,   int,   JspCompilationContext)   line:   526
JspServletWrapper.handleJspException(Exception)   line:   453
JspServletWrapper.service(HttpServletRequest,   HttpServletResponse,   boolean)   line:   371
JspServlet.serviceJspFile(HttpServletRequest,   HttpServletResponse,   String,   Throwable,   boolean)   line:   315
JspServlet.service(HttpServletRequest,   HttpServletResponse)   line:   265
JspServlet(HttpServlet).service(ServletRequest,   ServletResponse)   line:   803
ApplicationFilterChain.internalDoFilter(ServletRequest,   ServletResponse)   line:   269
ApplicationFilterChain.doFilter(ServletRequest,   ServletResponse)   line:   188
StandardWrapperValve.invoke(Request,   Response)   line:   210
Standa