zoukankan      html  css  js  c++  java
  • 学生管理系统----学生连接数据库类

    StudentDB.java:


    /**
     * @Title:StudentDB.java
     * @Package:com.you.student.system.utils
     * @Description:
     * @author:Youhaidong(游海东)
     * @date:2014-6-16 下午11:20:51
     * @version V1.0
     */
    package com.you.student.system.utils;
    
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Timestamp;
    
    import com.you.student.system.model.Student;
    
    /**
     * 类功能说明
     * 类修改者 修改日期
     * 修改说明
     * <p>Title:StudentDB.java</p>
     * <p>Description:游海东个人开发</p>
     * <p>Copyright:Copyright(c)2013</p>
     * @author:游海东
     * @date:2014-6-16 下午11:20:51
     * @version V1.0
     */
    public class StudentDB 
    {
    	private Connection conn = null;
    	private PreparedStatement psmt = null;
    	@SuppressWarnings("unused")
    	private ResultSet rs = null;
    	
    	/**
    	 * 获取连接数据库
    	 * @return the conn
    	 */
    	public Connection getConn() 
    	{
    		try 
    		{
    			if(this.conn == null || this.conn.isClosed())
    			{
    				DataBaseConn db = new DataBaseConn();
    				this.conn = db.getConn();
    			}
    		} 
    		catch (SQLException e) 
    		{
    			e.printStackTrace();
    		}
    		return conn;
    	}
    	
    	/**
    	 * 
    	 * @Title:addStu
    	 * @Description:
    	 * @param:@param stu
    	 * @param:@return
    	 * @return:Student
    	 * @throws
    	 */
    	public Student addStu(Student stu)
    	{
    		String sql = "";
    		String sql0 = "";
    		try 
    		{
    			psmt = this.getConn().prepareStatement(sql);
    			psmt.setString(2, stu.getStuName());
    			psmt.setString(3, stu.getStuSex());
    			psmt.setTimestamp(4, new Timestamp(stu.getBirthday().getTime()));
    			psmt.setString(5, stu.getProfessional());
    			psmt.setDouble(6, stu.getScore());
    			psmt.setString(7, stu.getRemarks());
    			psmt.execute();
    			psmt = this.getConn().prepareStatement(sql0);
    			psmt.setString(1, stu.getStuName());
    			psmt.setBytes(2, stu.getPhoto());
    		} 
    		catch (SQLException e) 
    		{
    			e.printStackTrace();
    		}
    		finally
    		{
    			try 
    			{
    				//关闭PreparedStatement对象
    				psmt.close();
    			} 
    			catch (SQLException e) 
    			{
    				e.printStackTrace();
    			}
    			try 
    			{
    				//关闭Connection对象
    				conn.close();
    			} 
    			catch (SQLException e) 
    			{
    				e.printStackTrace();
    			}
    		}
    		return stu;
    	}
    
    }
    


  • 相关阅读:
    寻找两个有序数组的中位数
    JAVA设计模式(组合模式)
    excel 操作
    研究生英语-春
    cvs
    Spring课程安排
    Spring的事务管理
    在WEB项目中集成Spring
    计算机网络参考模型
    揭开5G神秘面纱
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13315019.html
Copyright © 2011-2022 走看看