Download Untitled

Transcript
59
// CLASS spotdata to generate XML result from database.
package org.sunspotworld;
import
import
import
import
import
import
import
import
com.sun.spot.peripheral.radio.RadioFactory;
com.sun.spot.peripheral.radio.*;
com.sun.spot.io.j2me.radiostream.*;
com.sun.spot.io.j2me.radiogram.*;
com.sun.spot.util.IEEEAddress;
com.sun.spot.peripheral.TimeoutException;
com.sun.spot.util.IEEEAddress;
javax.microedition.io.*;
import com.sun.spot.*;
import
import
import
import
import
import
import
java.io.*; import java.lang.*; import java.net.*;
java.util.*;
java.sql.*;
java.sql.DriverManager;
java.sql.Connection;
java.sql.SQLException;
org.postgresql.Driver;
public class spotdata {
public void run() throws Exception{
try {
Class.forName("org.postgresql.Driver");
System.out.println("Generating SunSpot XML-DATA of Sensors...");
Connection c= null;
c =
DriverManager.getConnection("jdbc:postgresql://localhost:5432/task",
"postgres", "b0331969");
Statement select = c.createStatement();
String sqlxmlquery = "select xmlelement(name Sensor,xmlelement(name
NodeId, c.nodeid),"+
"xmlelement(name Xaxis, c.xaxis),xmlelement(name Yaxis, c.yaxis),"+
"xmlelement(name Zaxis, c.zaxis),xmlelement(name Temp, c.temp),"+
"xmlelement(name Light, c.light),"+
"xmlelement(name Time, c.modtime)) from spot_result c where
nodeid='0014.4F01.0000.6A40';";
ResultSet result1 = select.executeQuery(sqlxmlquery);
//Debugging System.out.println(result1);
while (result1.next()) {
String outputsunspot= result1.getString(1);
System.out.println(outputsunspot);
File spot1 = new File("C:/Documents and
Settings/Admin/Desktop/webdump/xml_sensor_result/spotresult1.xml");