通过JSP将数据推送到我的数据库给我ClassNotFoundException,而从main方法解析数据工作得很好。
我有我的mysql-connector jar和一切就绪,
在下面的类中,几乎没有打开/关闭数据库连接的方法。
package com.socialhub.dao;
import java.sql.Connection;
import java.sql.DriverManager;
public class DBConnection {
public static int client = 0;
public static Connection getConnection() {
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/socialhub","root","root");
client++;
} catch (Exception e) {
System.out.println("Connection issue " + e.getMessage());
e.printStackTrace();
}
return con;
}
public void closeConnection(Connection conn) {
try {
conn.close();
client--;
} catch (Exception e) {
System.out.println("Connection Close Issue" + e.getMessage());
}
}
public int getClient() {
return client;
}
}
<%@ page import="com.socialhub.action.Service"%>
<%
String username=request.getParameter("uname");
String fullname=request.getParameter("fname");
String password=request.getParameter("password");
String country=request.getParameter("country");
String gender=request.getParameter("gender");
Service service=new Service();
String message="";
int valid=0;
try {
country.length();
}
catch(Exception e) {
country="na";
}
if(country.equalsIgnoreCase("na")||country.equalsIgnoreCase("null")||country==null) {
message="Invalid Username and Password";
valid=service.checkcredential(username,password);
if(valid==0) {
response.sendRedirect("profile.jsp");
} else {
response.sendRedirect("login.jsp?message="+message);
}
}
else {
valid=service.save(fullname, country, gender, username, password);
if(valid==1) {
message="Registration Successfully completed";
response.sendRedirect("login.jsp?message="+message);
}
else {
message="Some Server Error";
response.sendRedirect("login.jsp?message="+message);
}
}
%>