这是getValidationValue 类的代码,从表单得到信息
package validationServer;
import com.opensymphony.xwork2.Action;
public class getValidationValue implements Action{
private getValidationValue InfoValue;
public String username;
public String password1;
public String password2;
public String email;
private boolean booleanValue;
private String returnValue;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword1() {
return password1;
}
public void setPassword1(String password1) {
this.password1 = password1;
}
public String getPassword2() {
return password2;
}
public void setPassword2(String password2) {
this.password2 = password2;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String execute() throws Exception {
// TODO 自动生成的方法存根
booleanValue=ValidationServer.query(getUsername());
if(booleanValue==true)
returnValue="error";
else{
booleanValue=ValidationServer.setValidationValue(InfoValue);
if(booleanValue==true)
returnValue="success";
else
returnValue="validationError";
}
return returnValue;
}
}
这是ValidationServer 类.getValidationValue 类得到表单信息后执行execute()这个方法后访问ValidationServer 类进行连接数据库,可是总是失败出现这句话The server encountered an internal error that prevented it from fulfilling this request.这是什么错误啊,是权限问题吗???求帮助
package validationServer;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class ValidationServer {
public static Connection conn;
private static String getServerUser="root";
private static String getServerPassword="password";
public static Connection getConnection(){
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("数据驱动加载成功");
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
System.out.println("数据驱动加载失败");
}
try {
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/student_1?useUnicode=true&characterEncoding=utf-8&useSSL=false", getServerUser, getServerPassword);
System.out.println("数据连接成功");
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
System.out.println("数据连接失败");
}
return conn;
}
public static boolean query(String username){
getConnection();
PreparedStatement sql;
try {
sql=conn.prepareStatement("select * from user where userName=?");
sql.setString(1, username);
if(sql.executeQuery()!=null){
conn.close();
System.out.println("数据连接关闭");
return true;
}else{
conn.close();
System.out.println("数据连接关闭");
return false;
}
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return false;
}
public static boolean setValidationValue(getValidationValue InfoValue){
getConnection();
PreparedStatement sql;
int value;
try {
sql=conn.prepareStatement("insert into user values(?,?,?)");
sql.setString(1, InfoValue.getUsername());
sql.setString(2, InfoValue.getPassword1());
sql.setString(3, InfoValue.getEmail());
value=sql.executeUpdate();
if(value==1)
return true;
conn.close();
System.out.println("数据连接关闭");
} catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
return false;
}
}