运行时直接跳到 catch(Exception e)里的  数据库连接错误 <%@ page contentType="text/html;charset=gb2312" language="java"%> 
<%@ page session="true"%> 
<%@ page import="java.sql.*"%> 
<% request.setCharacterEncoding("GB2312");%> 
<html> <body bgcolor="#ccccff"> 
<% 
      ResultSet rs=null; 
  String strSql=null;
    
    try{ 
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
     }
  catch(ClassNotFoundException e)
  {
     out.print("类找不到!");
  }
 
  try{
      Connection conn=DriverManager.getConnection("jdbc:odbc:testlzw", "system", "lzw123");        Statement stmt=conn.createStatement(); 
      String s_username=request.getParameter("username"); 
      strSql="select * from userTable where user_name="+"'"+s_username+"'"; 
      rs=stmt.executeQuery(strSql); 
     
  if(rs.next()){ 
      %> 
  <h2>对不起,你注册的账号已经存在</h2></centre><br><br> 
  <center><a href="Regist.jsp""Regist.jsp\">重新注册</a><br><br><a href="index.jsp">进入登录页面</a><br></center><br> 
  <% 
  }else{ 
  String s_password=request.getParameter("password"); 
  String s_email=request.getParameter("email"); 
  String s_sex=request.getParameter("sex"); 
  String s_age=request.getParameter("age"); 
 
  strSql = "insert into userTable (user_name,user_password,user_sex,user_email,user_age) values('"+s_username+"','"+s_password+"','"+s_sex+"','"+s_email+"','"+s_age+"')"; 
  int temp = stmt.executeUpdate(strSql);   
  if(temp>0){ 
%> 
          <center><h2 color=red>恭喜你注册成功!</h2></center><br><br> 
          <center><a href="index.jsp""index.jsp\"> 进入登录页面 </a></center> 
<% 
  }else { 
%> 
  <center><h2 color=red>对不起,注册失败!</h2></center><br><br> 
  <center><a href="Regist.jsp""Regist.jsp\">返回</a></center> 
<%    
  } 
  }   
      rs.close(); 
      stmt.close(); 
      conn.close(); 
      } 
      catch(Exception e){ 
      e.printStackTrace(); 
%> 
      <h2 align=center>数据库连接错误</h2> 
<%      
      } 
%> </body> 
</html> 

解决方案 »

  1.   

    没有报错,我注册完以后提交给这个页面检测,就直接输出我catch里面的内容了,是不是没有访问数据库呢
      

  2.   

    没玩过odbc不过你这个<h2 align=center>数据库连接错误</h2> 
    异常范围太大了, 把控制台的异常信息贴出来
      

  3.   

    我是用DW写的,在浏览器预览的时候,没报错,就直接输出catch,这是什么情况,是不是压根就没进行数据库操作呀。
      

  4.   

    额 ,加个调试语句看看Connection conn=DriverManager.getConnection("jdbc:odbc:testlzw", "system", "lzw123");  
    if(conn==null){
    %> 
          <h2 align=center>conn是空的</h2> 
    <%
    }
     Statement stmt=conn.createStatement(); 
      

  5.   

    Connection conn=DriverManager.getConnection("jdbc:odbc:testlzw", "system", "lzw123"); 
    %>  
      <h2 align=center>如果没有输出我,就是上一句出异常拉</h2>  
    <% 
    if(conn==null){
    %>  
      <h2 align=center>conn是空的</h2>  
    <%
    }
     Statement stmt=conn.createStatement();  
      

  6.   

    那就对了嘛,  <h2 align=center>如果没有输出我,就是上一句出异常拉</h2>  就是说明Connection conn=DriverManager.getConnection("jdbc:odbc:testlzw", "system", "lzw123"); 这一句出异常了,检察参数,
      

  7.   

    参数也没错啊,testlzw是我的数据源,system是数据库用户名 lzw123是我的密码~~~~~我在netbeans中测试了这个连接,有用啊,奇怪!!