It is my Computer Notes. Using Guide : object-key or object-key-key e.g. Step 1 Blog Search : [mysql-run] and then Step 2 ctrl+F [mysql-run] {bookMark me : Ctrl+D}
2013年9月9日 星期一
java-mysql-table2array
java mysql table to array
static double[][] dRaws=null;
static void getSQLData(){
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection
("jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=UTF8","userID", "Password");
stmt = con.createStatement();
rs = stmt.executeQuery("select Tcode,UNIX_TIMESTAMP(date)*1000,field1,
field2, field3, field4,
field5,field6 from TableName where Tcode="+code+" ;");
while (rs.next()){String id=rs.getString(1);}rs.last(); //go bottom
int rowCount=rs.getRow(); //go recno
dRaws = new double[rowCount][];
rs.beforeFirst(); //go top
int iRecno=0;
while (rs.next()){
dRaws[iRecno] = new double [6+10]; //append blank
for (int j=2; j<=7; j++){
try{dRaws[iRecno][j-2]=(double) rs.getDouble(j);} //replace field with value
catch (NullPointerException e){};
}
++iRecno;
}
con.close();
} catch (Exception e) {e.printStackTrace();}
}
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言