?? datapool.java~1~
字號:
package java2d;
import javax.sql.*;
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 + -