整个代码如下:
package database;
import java.sql.*;public class databasebean
{
 
 private Connection connection=null;
 private Statement statement=null;
 private ResultSet resultset=null;
 public databasebean()
 {
  Class.forName("com.mysql.jdbc.Driver").newInstance();
  connection=DriverManager.getConnection("jdbc:mysql://127.0.0.1.3306/cdj","root","");
  statement=connection.createStatement();
 }
 
  public boolean loginuser(String username,String userpassword)
  {
   boolean userExist=false;
   try
   {
    String strSql="select*from user where uID='"+username+"' and uPS='"+userpassword+"'";
    resultset=statement.executeQuery(strSql);
    
    if(resultset.next())
    {
     userExist=true;
     connection.close();
    }
    return userExist;
   }catch(SQLException e){
      e.printStack();           //有错
    connection.close();
    return false;
   }
  }
   }                           //有错
 /**
  * @param args
  */
 public static void main(String[] args) {
 
  // TODO Auto-generated method stub }} 为什么会错呀

解决方案 »

  1.   

    type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: Servlet execution threw an exception
    root cause java.lang.Error: Unresolved compilation problems: 
    The method printStack() is undefined for the type SQLException
    Syntax error on token "}", delete this token database.databasebean.<init>(databasebean.java:32)
    check.doPost(check.java:79)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      

  2.   

      e.printStack(); 
    ->
       e.printStackTrace(); 
      

  3.   

    为什么有错?因为你发明了个SQLException不存在的方法并使用之。
      

  4.   

    The method is printStack() undefined for the type SQLException
    方法printStack() 没有定义要学会自己看错误提示。
      

  5.   

    你的main函数下面不是还有个括号跟public class 哪里的对应吗?你把有错的那个删掉,就是main前面那个
      

  6.   

    e.printStack();          //有错 
    你自己都标明了错误!
      

  7.   

    我把那个括号去掉以后 出现 如下错误了哦Class.forName("com.mysql.jdbc.Driver").newInstance();
    connection=DriverManager.getConnection("jdbc:mysql://127.0.0.1.3306/cdj","root","");
    statement=connection.createStatement();connection.close();这四行都有错误提示错误原因:
    message description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: Servlet execution threw an exception
    root cause java.lang.Error: Unresolved compilation problems: 
    Unhandled exception type ClassNotFoundException
    Unhandled exception type InstantiationException
    Unhandled exception type IllegalAccessException
    Unhandled exception type SQLException
    Unhandled exception type SQLException
    Unhandled exception type SQLException database.databasebean.<init>(databasebean.java:12)
    check.doPost(check.java:79)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      

  8.   

    前面的 servlet 应该正确的吧   莫非是 servlet(文件名是check.java) 和这个javabean(文件名是databasebean.java,并且是在database包下面的) 连接有错??check.java 内容如下:import java.io.IOException;
    import java.io.PrintWriter;
    import database.databasebean;import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class check extends HttpServlet { /**
     * Constructor of the object.
     */
    public check() {
    super();
    } /**
     * Destruction of the servlet. <br>
     */
    public void destroy() {
    super.destroy(); // Just puts "destroy" string in log
    // Put your code here
    } /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out
    .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
    out.println("<HTML>");
    out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
    out.println("  <BODY>");
    out.print("    This is ");
    out.print(this.getClass());
    out.println(", using the GET method");
    out.println("  </BODY>");
    out.println("</HTML>");
    out.flush();
    out.close();
    } /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException { response.setContentType("text/html,");
    response.setCharacterEncoding("utf-8"); 
    PrintWriter out = response.getWriter();
    out
    .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
    out.println("<HTML>");
    out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
    out.println("  <BODY>");

    databasebean database=new databasebean();
    String username=request.getParameter("name");
    String userps=request.getParameter("password");
    try{
    if(database.loginuser(username, userps)){
    out.write(username+",你已登陆成功!");
    }
    }catch(Exception e){
    out.println("输入的用户名或密码有误!");
    }


    out.print("    This is ");
    out.print(this.getClass());
    out.println(", using the POST method");
    out.println("  </BODY>");
    out.println("</HTML>");
    out.flush();
    out.close();
    } /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    public void init() throws ServletException {
    // Put your code here
    }}
    劳烦大虾们帮忙啊, 刚开始学jsp,一些基本错误还不太会解决
      

  9.   

    public databasebean()
    {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      connection=DriverManager.getConnection("jdbc:mysql://127.0.0.1.3306/cdj","root","");
      statement=connection.createStatement();

    ->
    public databasebean()
    {
     try{
     //以下语句有异常必须catch,看你的报错就知道了
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      connection=DriverManager.getConnection("jdbc:mysql://127.0.0.1.3306/cdj","root","");
      statement=connection.createStatement();
    }catch(Exception e){
      e.printStackTrace();
    }
      

  10.   

    恩 页面逻辑终于正确了,可以显示了, 可我怎么输入了表中的正确用户名 和密码后还是会显示 那句 输入错误的提示啊??mysql> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | cdj                |
    | mysql              |
    | student1           |
    | test               |
    | testdb             |
    +--------------------+
    6 rows in set (0.01 sec)mysql> use cdj;
    Database changedmysql> select* from user;
    +------+------+
    | uID  | uPS  |
    +------+------+
    | qqq  | 123  |
    +------+------+这个是MYSQL中 的数据  应该没有错误吧