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