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

📄 datapool.java

📁 风机在线监测系统,采用sqlserver数据库,有问题联系我
💻 JAVA
字号:
package java2d;

import java.sql.*;

/**
 * <p>Title: 在线监测</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: embed</p>
 *
 * @author andy
 * @version 1.0
 */
public class dataPool {
    Connection con;
    static float E;
    float F;
    String S;
    dataPool() {
        getdataConnection();

    }

    public void getdataConnection() {
        Connection con;
        PreparedStatement ps;
        ResultSet rs;
        try {
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            this.con = DriverManager.getConnection("jdbc:microsoft:sqlserver://202.114.246.250:1433;DatabaseName=Fan_Remote_Monitoring",
                    "sa", "24RM849");
            System.out.println("con is ok!");

        } catch (Exception e) {
            e.printStackTrace();

        }
    }

    //if query table except "par_table"
    public float getdataF(String field, String table) {
        PreparedStatement ps;
        ResultSet rs;
        try {
            ps = con.prepareStatement("select " + field + " from " + table +
                                      " where ID='1'");
            rs = ps.executeQuery();
            while (rs.next()) {
                F = rs.getFloat(field);
            }

            rs.close();
            ps.close();
            return F;
        } catch (Exception e) {
            e.printStackTrace();
            return E;
        }
    }

    public float[] getdataF(String table) {
        PreparedStatement ps;
        ResultSet rs;
        float[] data = new float[7];
        try {
            ps = con.prepareStatement("select * from " + table +
                                      " where ID='1'");
            rs = ps.executeQuery();
            while (rs.next()) {
                if (table.compareTo("high_frequency_table") == 0) {
                    data[0] = rs.getFloat("Z1");
                    data[1] = rs.getFloat("Z2");
                    data[2] = rs.getFloat("Z3");
                    data[3] = rs.getFloat("Z4");
                    data[4] = rs.getFloat("S1");
                    data[5] = rs.getFloat("S2");
                } else if (table.compareTo("low_frequency_table") == 0) {
                    data[0] = rs.getFloat("T1");
                    data[1] = rs.getFloat("T2");
                    data[2] = rs.getFloat("T3");
                    data[3] = rs.getFloat("T4");
                    data[4] = rs.getFloat("R1");
                    data[5] = rs.getFloat("P1");
                    data[6] = rs.getFloat("P2");
                }

            }

            rs.close();
            ps.close();
            return data;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }


    public String getdataT(String table) {
        PreparedStatement ps;
        ResultSet rs;
        String field = "Samptime";
        try {
            ps = con.prepareStatement("select " + field + " from " + table +
                                      " where ID='1'");
            rs = ps.executeQuery();
            while (rs.next()) {
                S = rs.getString(field);
            }

            rs.close();
            ps.close();
            return S;
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }


    public void closeConnection() {
        try {
            con.close();
            System.out.println("connection has closed");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }


}

⌨️ 快捷键说明

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