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;
}
}
...全文
253 2 打赏 收藏 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
当作看不见 2016-10-22
  • 打赏
  • 举报
回复
,可是总是失败出现这句话The server encountered an internal error that prevented it from fulfilling this request.这是什么错误啊,是权限问题吗???求帮助 服务器常见错误500,不太懂这个
幻天天 2016-10-22
  • 打赏
  • 举报
回复
楼主:网上等待
代码下载链接: https://pan.quark.cn/s/a8fbca3925b4 《鸿蒙OS开发环境构建》指南系统性地阐述了配置和筹备鸿蒙OS开发所需的各种工具和条件的具体方法。鸿蒙OS,亦称HarmonyOS,是由华为研发的一款面向全场景的分布式操作系统,其目标是提供跨平台、多设备间无缝协作的使用体验。本指南涉及了从Linux服务器到Windows工作站的完整开发流程。指南中提及了MobaXterm,这是一款用于连接Linux源码服务器的软件,使得开发人员能够在Windows环境中远程访问Linux服务器。同时,HiTool作为烧录工具,用于将编译后的系统镜像写入开发板。IPOP.EXE则是一款串口终端软件,用于执行串行通信和调试任务。Embedded Studio用于开发设备驱动程序,而DevEco Studio是华为提供的图形化应用程序开发平台,支持C/C++语言,拥有代码编辑、编译、烧录和调试功能,被视为OpenHarmony智能设备开发者的首选集成开发环境。在硬件配置方面,指南列出了必需的设备,包括Linux服务器(推荐Ubuntu 16.04及以上版本),Windows工作台(兼容XP/7/10),以及Hi3518EV300 IoT Camera单板。开发期间,Windows工作台通过USB线与单板相连接,以实现数据传输。此外,为了开展开发工作,还需要安装putty、IPOP、tftp服务器等辅助软件,以及HiTool用于烧录操作。在软件系统要求方面,Linux服务器需要安装bash、Python3.7+、gn、ninja、LLVM等构建工具,这些工具对于生成和执行编译脚本具有关键作用。在Windows工作台上,建议采用Visual Studi...

5,657

社区成员

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

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