<%@ page contentType="text/html;charset=gb2312"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>教学考勤系统</title>
</head>
<body>
<center>
<%@ page language="java" import="java.sql.*"%>
<jsp:useBean id="userin" scope="page" class="DataBase.login"/>
<%  
  userin.opencon("teacher","sa","831010001");
  String user=request.getParameter("userID");
  String passwd=request.getParameter("password");
  String sql="selece * from teacher where name='"+user+"'";
  ResultSet rs=userin.executeQuery(sql);
  
  if(rs.next())
  {rs.close();
 %>
  <jsp:forward page="error.htm"/>
<%}
 else
 {
 <jsp:forward page="success.jsp"/>
 %>
<body> <%}%>
</body>
</body>
</html>

解决方案 »

  1.   

    还有不知道楼哥           
                Class.forName("oracle.jdbc.driver.OracleDriver");
                connection _conn = DriverManager.getConnection(url, uid, pwd);
    之类的驱动写了没有
      

  2.   

    是在不好意思,我是个新手,不知道怎么发贴子,请指教,我也有又一个问题,希望大家指点一二。下面是一个连接Access数据库的程序,数据源已经正确设置。
    <%@ page contentType="text/html;charset=GB2312"%>
    <%@ page import="java.sql.*"%>
    <html>
    <head>
    <title>
    </title>
    </head>
    <body>
    <%
          try{
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
          out.println("连接成功");
           }
          catch(Exception e){out.println("连接不成功");}
          try{
          Connection con=DriverManager.getConnection("jdbc:odbc:user","","");
          out.println("数据库连接成功");
           }catch(Exception e){out.println("URL错误");}
          try{
          Statement state=con.createStatement();
          out.println("陈述成功");
          }catch(Exception e){out.println("陈述问题");}
           
      %>
     </body>
     </html>
    上述是调用过程,但在运行时怎么出错呢,出错信息如下:
    org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 9 in the jsp file: /2.jspGenerated servlet error:
        [javac] Compiling 1 source fileD:\Tomcat\work\Catalina\localhost\test\org\apache\jsp\_2_jsp.java:53: cannot resolve symbol
    symbol  : variable con 
    location: class org.apache.jsp._2_jsp
          Statement state=con.createStatement();
                          ^
    1 error
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:127)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
    org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:415)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:458)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:552)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)请大家给点建议。
      

  3.   

    楼上的,你的问题应该是配置JDK的出错
      

  4.   

    try{
          Connection con=DriverManager.getConnection("jdbc:odbc:user","","");
          out.println("数据库连接成功");
           }catch(Exception e){out.println("URL错误");}
          try{
          Statement state=con.createStatement();==========================
    con变量出了作用域(只在try{}中有效)Connection con=null;
    try{
          con=DriverManager.getConnection("jdbc:odbc:user","","");
          out.println("数据库连接成功");
           }catch(Exception e){out.println("URL错误");}
          try{
          Statement state=con.createStatement();