JSP page calls JDBC-induced sqlexception

Source: Internet
Author: User

When you connect to a MySQL database locally, the previous method is to import the JDBC jar package directly into the project LIB, so that you can get a connection with just the following code.

        String user= "xxx";        String password= "123";        String URL= "jdbc:mysql://localhost:3306/xxx";        Connection con=null;        Try {            con=drivermanager.getconnection (url,user,password);         Catch (SQLException e) {            e.printstacktrace ();        }         return con;

The above call in the local use has been normal, but when the JSP page is written, the same steps, import jar package into LIB, database Operation class Test function is normal, but the browser in the call database will appear SqlException, review several times after the code has not found where the problem occurs, when the following code is added , problem solving. Presumably on the server side, when the database is called, even if the package is imported, the classes used are not automatically loaded. Ask the great God to correct me.

       try{             //            class.forname ("Com.mysql.jdbc.Driver");         } Catch (ClassNotFoundException e) {             System.out.println ("Driver class not found, load driver failed!") ");             E.printstacktrace ();         }

JSP page calls JDBC-induced sqlexception

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.