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

📄 selectoperate.java

📁 用java编写的人事管理系统,很好的 学习下吧
💻 JAVA
字号:
/**
 * 源文件:SelectOperate.java
 * 作用:查询
 */
package mypro;

import java.sql.*;
import java.util.*;
import javax.swing.*;

public class SelectOperate
{
	private Connection con=DatabaseConnection.getConnection();
	/*通过表名和一个查询条件进行查询*/
	public Vector getDataByOneColname(String tabname,String colname,String strdate)
    {
        Vector ver = new Vector();
        try
        {
            String strSql = "SELECT * FROM [" +tabname+"] where "+colname+"=?";
            PreparedStatement ps=con.prepareStatement(strSql);
            ps.setString(1,strdate);
            ResultSet rs = ps.executeQuery();
            int cols = rs.getMetaData().getColumnCount();
            while (rs.next())
            {
                Vector vec = new Vector();
                for (int i = 1; i <= cols; i++)
                {
                    vec.add(rs.getObject(i));
                }
                ver.add(vec);
            }
            rs.close();
            ps.close();
        }
        catch (SQLException sqle)
        {
        	JOptionPane.showMessageDialog(null,"表中无此列","提示",JOptionPane.INFORMATION_MESSAGE);
        }
        return (ver);
    }
    /*通过表名和一个查询条件进行查询,方法重载*/
    public Vector getDataByOneColname(String tabname,String colname,int strdate)
    {
        Vector ver = new Vector();
        try
        {
            String strSql = "SELECT * FROM [" +tabname+"] where "+colname+"=?";
            PreparedStatement ps=con.prepareStatement(strSql);
            ps.setInt(1,strdate);
            ResultSet rs = ps.executeQuery();
            int cols = rs.getMetaData().getColumnCount();
            while (rs.next())
            {
                Vector vec = new Vector();
                for (int i = 1; i <= cols; i++)
                {
                    vec.add(rs.getObject(i));
                }
                ver.add(vec);
            }
            rs.close();
            ps.close();
        }
        catch (SQLException sqle)
        {
            JOptionPane.showMessageDialog(null,"表中无此列","提示",JOptionPane.INFORMATION_MESSAGE);
        }
        return (ver);
    }
    /*通过表名和一个查询条件和符号进行查询,方法重载*/
    public Vector getDataByOneColname(String tabname,String colname,String mark,double strdate)
    {
        Vector ver = new Vector();
        try
        {
            String strSql = "SELECT * FROM [" +tabname+"] where "+colname+mark+"?";
            PreparedStatement ps=con.prepareStatement(strSql);
            ps.setDouble(1,strdate);
            ResultSet rs = ps.executeQuery();
            int cols = rs.getMetaData().getColumnCount();
            while (rs.next())
            {
                Vector vec = new Vector();
                for (int i = 1; i <= cols; i++)
                {
                    vec.add(rs.getObject(i));
                }
                ver.add(vec);
            }
            rs.close();
            ps.close();
        }
        catch (SQLException sqle)
        {
            JOptionPane.showMessageDialog(null,"表中无此列","提示",JOptionPane.INFORMATION_MESSAGE);
        }
        return (ver);
    }
    /*通过品牌、型号、状态、颜色进行查询*/
    public Vector getDataByMamasac(String tabname,SelectData sd)
    {
        Vector ver = new Vector();
        try
        {
            String strSql = "SELECT * FROM [" +tabname+"] where 品牌=? and 型号=? and 状态=? and 颜色=?";
            PreparedStatement ps=con.prepareStatement(strSql);
            ps.setString(1,sd.getMsn());
            ps.setString(2,sd.getmModel());
            ps.setString(3,sd.getState());
            ps.setString(4,sd.getColor());
            ResultSet rs = ps.executeQuery();
            int cols = rs.getMetaData().getColumnCount();
            while (rs.next())
            {
                Vector vec = new Vector();
                for (int i = 1; i <= cols; i++)
                {
                    vec.add(rs.getObject(i));
                }
                ver.add(vec);
            }
            rs.close();
            ps.close();
        }
        catch (SQLException sqle)
        {
            JOptionPane.showMessageDialog(null,"表中无此列","提示",JOptionPane.INFORMATION_MESSAGE);
        }
        
        return (ver);
    }
    /*通过品牌、型号、颜色进行查询*/
    public Vector getDataByMamac(String tabname,SelectData sd)
    {
        Vector ver = new Vector();
        try
        {
            String strSql = "SELECT * FROM [" +tabname+"] where 品牌=? and 型号=? and 颜色=?";
            PreparedStatement ps=con.prepareStatement(strSql);
            ps.setString(1,sd.getMsn());
            ps.setString(2,sd.getmModel());
            ps.setString(3,sd.getColor());
            ResultSet rs = ps.executeQuery();
            int cols = rs.getMetaData().getColumnCount();
            while (rs.next())
            {
                Vector vec = new Vector();
                for (int i = 1; i <= cols; i++)
                {
                    vec.add(rs.getObject(i));
                }
                ver.add(vec);
            }
            rs.close();
            ps.close();
        }
        catch (SQLException sqle)
        {
            JOptionPane.showMessageDialog(null,"表中无此列","提示",JOptionPane.INFORMATION_MESSAGE);
        }
        
        return (ver);
    }
    /*通过品牌、状态、颜色进行查询*/
    public Vector getDataByMasac(String tabname,SelectData sd)
    {
        Vector ver = new Vector();
        try
        {
            String strSql = "SELECT * FROM [" +tabname+"] where 品牌=? and 状态=? and 颜色=?";
            PreparedStatement ps=con.prepareStatement(strSql);
            ps.setString(1,sd.getMsn());
            ps.setString(2,sd.getState());
            ps.setString(3,sd.getColor());
            ResultSet rs = ps.executeQuery();
            int cols = rs.getMetaData().getColumnCount();
            while (rs.next())
            {
                Vector vec = new Vector();
                for (int i = 1; i <= cols; i++)
                {
                    vec.add(rs.getObject(i));
                }
                ver.add(vec);
            }
            rs.close();
            ps.close();
        }
        catch (SQLException sqle)
        {
            JOptionPane.showMessageDialog(null,"表中无此列","提示",JOptionPane.INFORMATION_MESSAGE);
        }
        
        return (ver);
    }
    /*通过品牌、型号、状态进行查询*/
    public Vector getDataByMamas(String tabname,SelectData sd)
    {
        Vector ver = new Vector();
        try
        {
            String strSql = "SELECT * FROM [" +tabname+"] where 品牌=? and 型号=? and 状态=?";
            PreparedStatement ps=con.prepareStatement(strSql);
            ps.setString(1,sd.getMsn());
            ps.setString(2,sd.getmModel());
            ps.setString(3,sd.getState());
            ResultSet rs = ps.executeQuery();
            int cols = rs.getMetaData().getColumnCount();
            while (rs.next())
            {
                Vector vec = new Vector();
                for (int i = 1; i <= cols; i++)
                {
                    vec.add(rs.getObject(i));
                }
                ver.add(vec);
            }
            rs.close();
            ps.close();
        }
        catch (SQLException sqle)
        {
            JOptionPane.showMessageDialog(null,"表中无此列","提示",JOptionPane.INFORMATION_MESSAGE);
        }
        
        return (ver);
    }
    /*通过品牌、型号进行查询*/
    public Vector getDataByMam(String tabname,SelectData sd)
    {
        Vector ver = new Vector();
        try
        {
            String strSql = "SELECT * FROM [" +tabname+"] where 品牌=? and 型号=?";
            PreparedStatement ps=con.prepareStatement(strSql);
            ps.setString(1,sd.getMsn());
            ps.setString(2,sd.getmModel());
            ResultSet rs = ps.executeQuery();
            int cols = rs.getMetaData().getColumnCount();
            while (rs.next())
            {
                Vector vec = new Vector();
                for (int i = 1; i <= cols; i++)
                {
                    vec.add(rs.getObject(i));
                }
                ver.add(vec);
            }
            rs.close();
            ps.close();
        }
        catch (SQLException sqle)
        {
            JOptionPane.showMessageDialog(null,"表中无此列","提示",JOptionPane.INFORMATION_MESSAGE);
        }
        
        return (ver);
    }
    /*通过品牌、颜色进行查询*/
    public Vector getDataByMac(String tabname,SelectData sd)
    {
        Vector ver = new Vector();
        try
        {
            String strSql = "SELECT * FROM [" +tabname+"] where 品牌=? and 颜色=?";
            PreparedStatement ps=con.prepareStatement(strSql);
            ps.setString(1,sd.getMsn());
            ps.setString(2,sd.getColor());
            ResultSet rs = ps.executeQuery();
            int cols = rs.getMetaData().getColumnCount();
            while (rs.next())
            {
                Vector vec = new Vector();
                for (int i = 1; i <= cols; i++)
                {
                    vec.add(rs.getObject(i));
                }
                ver.add(vec);
            }
            rs.close();
            ps.close();
        }
        catch (SQLException sqle)
        {
            JOptionPane.showMessageDialog(null,"表中无此列","提示",JOptionPane.INFORMATION_MESSAGE);
        }
        
        return (ver);
    }
    /*通过品牌、状态进行查询*/
    public Vector getDataByMas(String tabname,SelectData sd)
    {
        Vector ver = new Vector();
        try
        {
            String strSql = "SELECT * FROM [" +tabname+"] where 品牌=? and 状态=?";
            PreparedStatement ps=con.prepareStatement(strSql);
            ps.setString(1,sd.getMsn());
            ps.setString(2,sd.getState());
            ResultSet rs = ps.executeQuery();
            int cols = rs.getMetaData().getColumnCount();
            while (rs.next())
            {
                Vector vec = new Vector();
                for (int i = 1; i <= cols; i++)
                {
                    vec.add(rs.getObject(i));
                }
                ver.add(vec);
            }
            rs.close();
            ps.close();
        }
        catch (SQLException sqle)
        {
            JOptionPane.showMessageDialog(null,"表中无此列","提示",JOptionPane.INFORMATION_MESSAGE);
        }
        
        return (ver);
    }
}

⌨️ 快捷键说明

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