Could not initialize class com.game.utli.JDBC
<%@ page import="org.omg.CORBA.Request" %><%--
Created by IntelliJ IDEA.
User: imagine
Date: 2018/1/15 0015
Time: 22:25
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import="com.demo.bean.Emp" %>
<%@ page import="com.demo.db.DbUtil,com.game.*" %>
<%@ page import="java.util.Map" %>
<%@ page import="javax.rmi.CORBA.Util" errorPage="error.jsp" %>
<%@ page import="com.game.entity.UserEntity" %>
<%@ page import="com.game.impdao.UserImpDao" %>
<html>
<head>
<title>人事管理系统</title>
</head>
<body>
<%
String user_pwd = request.getParameter("user_pwd");
String user_id = request.getParameter("user_id");
UserEntity userEntity;
UserImpDao userImpDao = new UserImpDao();
userEntity = userImpDao.Log_in(user_id,user_pwd);
if (userEntity == null){
userEntity.setUser_id("12");
userEntity.setUser_money(1);
userEntity.setUser_name("ds");
}else {
%>
<h3 align="center">欢迎来到人事管理系统</h3>
<%--<h3 align="right">访问量:<%=application.getAttribute("count")%></h3>--%>
<%--<h3 align="right">员工工号:<%=session.getAttribute("user_id")%></h3>--%>
<table align="center" border="1px" width="400px;">
<tr>
<td>id</td>
<td>name</td>
<td>money</td>
<td>update</td>
</tr>
<tr>
<td><%=userEntity.getUser_id()%></td>
<td><%=userEntity.getUser_name()%></td>
<td><%=""+ userEntity.getUser_money()%></td>
<td><a href="update.jsp?account=<%=userEntity.getUser_id()%>&name=<%=userEntity.getUser_id()%>&age=<%=userEntity.getUser_name()%>">修改</a></td>
</tr>
</table>
<%}%>
<%--// Emp emp = new Emp(null,null,account,password);--%>
<%--// Map<String,Emp> map = DbUtil.map;--%>
<%--// session.setAttribute("account",account);--%>
<%--// boolean flag = DbUtil.selectEmpByAcountAndPassword(emp);--%>
<%--// if (flag == true) {--%>
<%--// Object o = application.getAttribute("count");--%>
<%--// if (o == null){--%>
<%--// application.setAttribute("count",1);--%>
<%--// }else {--%>
<%--// int count = (int) o;--%>
<%--// application.setAttribute("count",count + 1);--%>
<%--// }--%>
<%--<%–<%–%>--%>
<%--// }else {--%>
<%--// throw new Exception("账号或密码错误");--%>
<%--// }--%>
<%--<%–%>–%>--%>
</body>
</html>
package com.game.utli;
import java.sql.*;
import java.sql.PreparedStatement;
public class JDBC {
private static String driver = "com.mysql.jdbc.Driver";
private static String url = "jdbc:mysql://115.28.169.57:3306/game?useUnicode=true&characterEncoding=utf-8&useSSL=false";
private static String user = "root";
private static String password = "Combat_10";
static {
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
e.printStackTrace();
throw new RuntimeException("数据库连接错误");
}
}
public static Connection getConnection() {
Connection con = null;
try {
con = DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException("");
}
// System.out.println("数据库连接成功");
return con;
}
/**
* add delete update
* @param sql
* @param args
* @return
*/
public static int executeUpdate(String sql,Object[] args){
Connection con = null;
PreparedStatement ps = null;
int number;
try {
con = JDBC.getConnection();
ps = con.prepareStatement(sql);
for (int i = 0;i < args.length;i++){
ps.setObject(i + 1,args[i]);
}
number = ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException("数据库错误");
} finally {
// JDBC.close(con);
// JDBC.close(ps);
}
return number;
}
/**
* select
* @param sql
* @param args
* @return
*/
public static ResultSet executeQuery(String sql,Object[] args){
Connection con = null;
PreparedStatement ps = null;
ResultSet res = null;
int number;
try {
con = JDBC.getConnection();
ps = con.prepareStatement(sql);
for (int i = 0;i < args.length;i++){
ps.setObject(i + 1,args[i]);
}
res = ps.executeQuery();
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException("数据库错误");
} finally {
// JDBC.close(con);
// JDBC.close(ps);
// JDBC.close(res);
}
System.out.printf(res+"");
return res;
}
/**
*
* @param con
*/
public static void close(Connection con) {
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException("con close");
}
}
/**
*
* @param res
*/
public static void close(ResultSet res) {
try {
res.close();
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException("res close");
}
}
/**
*
* @param ps
*/
public static void close(PreparedStatement ps) {
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException("sta close");
}
}
public static void main(String[] args) {
System.out.println("skhkh");
}
}
正在回答 回答被采纳积分+1
- 参与学习 716 人
- 提交作业 185 份
- 解答问题 1363 个
会Java?懂前端基础?想学后台开发?那么,赶快来学习《Java Web入门》路径吧。本路径主要介绍Java Web的基础知识,并配有大量案例,定会让你收获多多!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星