0
I am trying to make a web application using java,jsp,Servlets and database. But when I run as in addClient.jsp class this error appears:
HTTP Status 500- Internal Server Error.
I have looked on the internet how to solve and I can not find solution. Thanks for the help.
I created a Contact Class, a Servlet Createclient, Connectionfactory, Contactdao and addClient.jsp.
I put the code of some of the classes
contact class:
public class Contact {
private String name;
private String email;
private String address;
private int telephoneNumber;
public Contact() {
}
public Contact (String name, String email, String address, int phone) {
this.name=name;
this.email=email;
this.address=address;
this.telephoneNumber=phone;
}
//Getters e Setters
...
}
contactdao class:
public class ContactDAO {
private Connection con;
public Connection getConnection() {
return con;
}
public ContactDAO() {
ConnectionFactory conF = new ConnectionFactory();
con=conF.getBDConnection();
}
public void addClient(Contact contact) {
String sql= "INSERT INTO contatos" + "(nome,email,endereco,telefone)" +
"values (?,?,?,?)";
try {
PreparedStatement stmt= con.prepareStatement(sql);
stmt.setString(1,contact.getName());
stmt.setString(2,contact.getEmail());
stmt.setString(3,contact.getAddress());
stmt.setInt(4,contact.getTelephoneNumber());
stmt.executeUpdate();
stmt.close();
} catch (SQLException sqle) {
sqle.printStackTrace();
} finally {
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Connectionfactory class:
public class ConnectionFactory {
public Connection getBDConnection() {
Connection con = null;
System.out.println("Testing access to BD MySQL\n");
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb","root", "");
System.out.println("Connection successful!!!");
} catch (ClassNotFoundException cnfe){
cnfe.printStackTrace();
System.out.println("ClassNotFoundException");
} catch (SQLException sqle) {
sqle.printStackTrace();
System.out.println("SQLException");
}
return con;
}
public void closeConnection(Connection con) {
try {
con.close();
System.out.println("\n Connection successfully close!!!");
}
catch (SQLException sqle) {
System.out.println("SQLException");
}
}
}
have the server log stacktrace? Put it here to help people.
– lemoce