查询xml字段的类为readxml.java,该类通过提供cid来查询客户表中的info字段并产生xml文件。
package xml;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;public class readxml ...{
private static Connection conn;static Properties Db2ConnProps = new Properties();
private static PreparedStatement poStmt;
private static ResultSet rs;
static Properties fileinputProps = new Properties();public static void main(String[] args) throws FileNotFoundException,
IOException, SQLException ...{
String Db, userName, passwd, host, port,description;host = port = Db = userName = passwd = null;
/**//* load the contents of properties file in case of missing arguments*/
Db2ConnProps.load(new FileInputStream(
"F://eclipse//WorkPlace//Db2XML//src//Db2Conn.properties"));
Db = Db2ConnProps.getProperty("databaseName");
userName = Db2ConnProps.getProperty("userName");
passwd = Db2ConnProps.getProperty("password");
host = Db2ConnProps.getProperty("hostName");
port = Db2ConnProps.getProperty("portNumber");/**//** connect to the database **/
conn = Db2Conn.get(Db, userName, passwd, host, port);
int id = 99;
String fn = "F://eclipse//WorkPlace//Db2XML//src//Client8877.xml";
String sqls = "insert into customer ( cid, info) values (?, ?)";
File file = new File(fn);try ...{
System.out.print(getDescription("88"));} catch (RuntimeException e) ...{
// TODO Auto-generated catch block
e.printStackTrace();
} finally ...{
conn.close();
}}
public static String getDescription(String cid)
...{
String description;
description=null;
try
...{
poStmt = conn.prepareStatement("Select INFO from CUSTOMER where cid=?");
poStmt.setString(1,cid);
rs= poStmt.executeQuery();
if(rs.next())
...{
description=rs.getString(1);
}
else
System.out.println(" Customer info not found./n");
}
catch(SQLException sqle)
...{
System.out.println("Error Msg: "+ sqle.getMessage());
System.out.println("SQLState: "+sqle.getSQLState());
System.out.println("SQLError: "+sqle.getErrorCode());
System.out.println("Rollback the transaction and quit the program");
System.out.println();
try ...{conn.setAutoCommit(false);}
catch (java.sql.SQLException e)
...{
e.printStackTrace();
System.exit(-1);
}
try ...{ conn.rollback(); }
catch (Exception e)
...{
JDbcException jDbcExc = new JDbcException(e, conn);
jDbcExc.handle();
}
System.exit(1);
}
return description;
}
}
498)this.style.width=498;">