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

📄 searchdb.java

📁 仿校内网站
💻 JAVA
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package myTools.search;import ArticleSharing.*;import java.sql.*;import java.io.*;/** * * @author tiredsuddenly */public class SearchDB extends DBTools{    public SearchDB()    {        System.out.println("!!!!!!!!!!");        try        {            //super.            Class.forName("com.mysql.jdbc.Driver");            conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/dating_platform", "root", "1234");            stat = conn.createStatement();            System.out.println("connected successful!!!");        }        catch(Exception e)        {            e.printStackTrace();        }    }    public void closeConnection() throws SQLException    {        conn.close();    }    public ResultSet search(int year, String sex, String age_from, String age_to, String constellation, String marry, String blood, String education, String province, String city)throws SQLException, IOException    {                if(sex.equals("0"))  //search the female        {            searchDB = searchDB + " and sex = 0 ";        }        else if(sex.equals("1"))  //search the male        {            searchDB = searchDB + " and sex = 1 ";        }        //searching information about age        if(!age_from.equals("") && !age_to.equals("")) //sure the age wanted to search        {            int _age_from = Integer.parseInt(age_from);                        int _age_to = Integer.parseInt(age_to);            int bir_from = year - _age_to;            int bir_to = year - _age_from;            searchDB = searchDB + " and bir_year between " + bir_from + " and " + bir_to;        }        //searching infomation about constellation        if(!constellation.equals(""))        {            searchDB = searchDB + " and constellation = " + "\"" + constellation + "\"";        }        //searching information about marry        if(!marry.equals(""))        {            searchDB = searchDB + " and marriage = " + "\"" + marry + "\"";        }        //searching information about blood        if(!blood.equals(""))        {            searchDB = searchDB + " and blood_type = " + "\"" + blood + "\"";        }        //searching information about education        if(!education.equals(""))        {            searchDB = searchDB + " and education = " + "\"" + education + "\"";                 }        //searching information about province and city        if(!province.equals(""))        {            searchDB = searchDB + " and province = '" + province +  "' and city = '" +  city + "'";        }        System.out.println(searchDB);                try        {            rs = stat.executeQuery(searchDB);            System.out.println("search over");            while(rs.next())            {                System.out.print("what happen!!!");                System.out.println(rs.getInt(1));                System.out.println(rs.getString(2));                System.out.println(rs.getString(3));                System.out.println(rs.getInt(4));                System.out.println(rs.getInt(5));                System.out.println(rs.getString(6));                System.out.println(rs.getString(7));                System.out.println(rs.getString(8));                System.out.println(rs.getString(9));            }        }        catch(SQLException e)        {            e.getStackTrace();            System.out.println("~~~~~~~~~"+e.getMessage());        }        rs.beforeFirst();        return rs;    }    private Connection conn;    private ResultSet rs = null;    private Statement stat = null;    private String searchDB =             " select users.user_id, photo_path, user_name, sex, bir_year, province, city, marriage, self_description " +            " from users, identity_information " +            " where users.user_id = identity_information.user_id ";}

⌨️ 快捷键说明

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