tomcat连接mysql数据库总是失败

幻天天 2016-10-22 04:34:09
这是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;
}
}
...全文
207 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
当作看不见 2016-10-22
  • 打赏
  • 举报
回复
,可是总是失败出现这句话The server encountered an internal error that prevented it from fulfilling this request.这是什么错误啊,是权限问题吗???求帮助 服务器常见错误500,不太懂这个
幻天天 2016-10-22
  • 打赏
  • 举报
回复
楼主:网上等待

5,655

社区成员

发帖
与我相关
我的任务
社区描述
Web开发应用服务器相关讨论专区
社区管理员
  • 应用服务器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧