java——学生管理系统(maven web)

这是一个使用Maven构建的Java Web项目,实现了学生管理系统的功能。数据库采用MySQL,通过JDBC进行数据操作。PropertiesTool用于读取配置文件,DBLink类负责数据库连接,IRowMapper接口处理数据映射,Main.java为程序入口,db.properties和log4j.properties分别存储数据库和日志配置。
摘要由CSDN通过智能技术生成

1、项目结构:
在这里插入图片描述
2、数据库在这里插入图片描述

3、PropertiesTool.java:

package com.tool;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesTool {
   

	  private static Properties properties = new Properties();
	  
	  static {
   
	    InputStream inputStream = PropertiesTool.class.getClassLoader().getResourceAsStream("db.properties");
	    try {
   
	      properties.load(inputStream);
	    } catch (IOException e) {
   
	      e.printStackTrace();
	    }
	  }
	  
	  public static String getValue(String key) {
   
		  return properties.getProperty(key);
	  }
	 
}

4、DBLink.java:

package com.tool.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.log4j.Logger;

import com.jd.tool.PropertiesTool;

/**
 * 数据库管理工具类
 * 
 * @author 10164
 */
public class DBLink {
   
	
	private Logger logger=Logger.getLogger(DBLink.class);
	
	/**
	 * 获取数据库链接
	 * 
	 * @author 10164
	 */
	private Connection getConnection() {
   
		try {
   
			Class.forName("com.mysql.jdbc.Driver");
			String userName = PropertiesTool.getValue("db.username");
			String password = PropertiesTool.getValue("db.password");
			String url = PropertiesTool.getValue("db.url");
			return DriverManager.getConnection(url, userName, password);
		} catch (Exception e) {
   
			logger.debug(e.getMessage(),e);
		} 
		return null;
	}
	
	/**
	 * 查询数据
	 * 
	 * @author 10164
	 */
	public void select(String sql,IRowMapper rowMapper) {
   
	    Connection connection = null;
	    Statement statement =null;
	    ResultSet resultSet=null;
	    try {
   
	      connection=getConnection();
	      statement = connection.createStatement();
	      resultSet= statement.executeQuery(sql);
	      rowMapper.rowmapper(resultSet);
	    } catch (Exception e) {
   
	      logger.debug(e.getMessage(),e);
	    }finally {
   
	      close(resultSet,statement,connection);
	    }
	  }
	
	/**
	 * 修改数据
	 * 
	 * @author 10164
	 */
	public boolean update(String sql) {
   
		Connection connection=null;
		Statement statement=null;
		try {
   
			connection=getConnection();
			statement=connection.createStatement();
			int result=statement.executeUpdate(sql);
			//statement.close();
			//connection.close();
			return result>0;
		}catch(Exception e) {
   
			logger.debug(e
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值