Import the Java. SQL. Connection;
import java.sql.DriverManager;
Import of Java, SQL PreparedStatement;
Import the Java. SQL. SQLException;
Public class DAO {
Public int, update (String name, String PWD) {
The String URL="JDBC: mysql://localhost: 3306/new_db? UseUnicode=true& CharacterEncoding=utf-8 & amp; UseJDBCCompliantTimezoneShift=true& UseLegacyDatetimeCode=false& ServerTimezone=UTC ";
String USER="root";
String PWD="1987";
Try {
Class.forName("com.mysql.cj.jdbc.Driver");
The Connection Connection=DriverManager. GetConnection (URL, the USER, the PWD);
String SQL="insert into users values (?,?,?,?,? ,?) ";
PreparedStatement PSTMT=connection. PrepareStatement (SQL);
PSTMT. SetString (1, name);
PSTMT. SetString (2, PWD);
Int I=PSTMT. ExecuteUpdate ();
pstmt.close();
connection.close();
return i;
} the catch (a ClassNotFoundException e) {
e.printStackTrace();
The return - 2;
} the catch (SQLException e) {
e.printStackTrace();
return -1;
} the catch (Exception e) {
The return - 3;
}
}
}
Great god see, the above is my JSP, below is the Java code to access the page after printing is 2, namely into ClassNotFound exceptions, but running Java directly, not through the JSP is no exception