⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 indb.java

📁 股票投资管理系统
💻 JAVA
字号:
package db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import bean.InBean;

public class InDB {
	
	private Connection con;
	private Statement stm; 
	private PreparedStatement ps;
	private ResultSet rs;
	
	public InDB(){
		con = null;
		stm = null;
		ps = null;
		rs = null;
	}
	
	
	public boolean checkIn(InBean ib){
		con = ConDB.getCon();
		boolean flag = false;
		String sql = "select * from investment where user_name=? and in_name=?";
		try {
			ps = con.prepareStatement(sql);
			ps.setString(1, ib.getUser_name());
			ps.setString(2, ib.getIn_name());
			rs = ps.executeQuery();
			if(!rs.next())
				flag = true;
		} catch (SQLException e) {
			flag = false;
			e.printStackTrace();
		}
		
		
		try {
			rs.close();
			ps.close();
			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return flag;
	}
	
	
	public int insertIn(InBean ib){
		con = ConDB.getCon();
		int result = 0;
		String sql = "insert into investment values(default,?,?)";
		try {
			ps = con.prepareStatement(sql);
			ps.setString(1, ib.getUser_name());
			ps.setString(2, ib.getIn_name());
			result = ps.executeUpdate();
		} catch (SQLException e) {
			result = 0;
			e.printStackTrace();
		}
		
		try {
			ps.close();
			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return result;	
	}
	
	
	public InBean getInfo(InBean ib){
		con = ConDB.getCon();
		String sql = "select * from investment where user_name=? and in_name=?";
		try {
			ps = con.prepareStatement(sql);
			ps.setString(1, ib.getUser_name());
			ps.setString(2, ib.getIn_name());
			rs = ps.executeQuery();
			if(rs.next())
				ib.setIn_id(rs.getInt(1));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		try {
			rs.close();
			ps.close();
			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return ib;
		
	}
	
	
	public int delIn(InBean ib){
		con = ConDB.getCon();
		int result = 0;
		String sql = "delete from investment where user_name=? and in_name=?";
		try {
			ps = con.prepareStatement(sql);
			ps.setString(1, ib.getUser_name());
			ps.setString(2, ib.getIn_name());
			result = ps.executeUpdate();
		} catch (SQLException e) {
			result = 0;
			e.printStackTrace();
		}
		
		try {
			ps.close();
			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return result;
	}
	
	
	public ResultSet selectAll(InBean ib){
		con = ConDB.getCon();
		String sql = "select in_name from investment where user_name=?";
		try {
			ps = con.prepareStatement(sql);
			ps.setString(1, ib.getUser_name());
			rs = ps.executeQuery();		
		} catch (SQLException e) {	
			e.printStackTrace();
		}
		return rs;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -