当前位置: 技术问答>java相关
一个关于JAVA,XML的小程序,有点难?
来源: 互联网 发布时间:2015-07-15
本文导语: 各位大侠,为什么javac Connectprice的时候出错呢? 请各位帮忙调试好吗?最好能加上注解。本人将十分感激。如果正确立即送分 package bean; import java.io.*; import java.net.*; import java.util.*; import java.sql.*; public class Conne...
各位大侠,为什么javac Connectprice的时候出错呢?
请各位帮忙调试好吗?最好能加上注解。本人将十分感激。如果正确立即送分
package bean;
import java.io.*;
import java.net.*;
import java.util.*;
import java.sql.*;
public class Connectprice{
String backxml="";
ResultSet rset=null;
Connection conn =null;
Statement stmt =null;
String localname="",sql="";
String attribute="";
String flightNo="FlightNo",airline="";
String flightvalue="FlyDate",classes="";
String fromcity="FromCity";
String tocity="ToCity";
String startdate="DTime";
String enddate="";
//与服务器连接
public void sendxml(String xml){
Socket socket;
String len;
InputStream Is;
OutputStream Os;
DataInputStream DIS;
PrintStream PS;
try{
//向主机名为args[0]的服务器申请连接
//注意端口号要与服务器保持一致:1001
socket=new Socket("10.21.5.19",1001);
System.out.println("client ok");
System.out.println("************************************************");
System.out.println("");
//获得对应socket的输入/输出流
Is=socket.getInputStream();
Os=socket.getOutputStream();
//建立数据流
DIS=new DataInputStream(Is);
PS = new PrintStream(Os);
System.out.print("you say:"+xml);
PS.print(xml); //将读取得字符串传给server
System.out.println("");
System.out.println("please wait server`s message...");
System.out.println("");
backxml=DIS.readLine(); //从服务器获得字符串
System.out.println("server said:"+backxml); //打印字符串
//关闭连接
DIS.close(); //关闭数据输入流
PS.close(); //关闭数据输出流
Is.close(); //关闭输入流
Os.close(); //关闭输出流
socket.close(); //关闭socket
}
catch(Exception e){
System.out.println("连接Error:"+e);
}
}
//建立xml文档
public void writexml(){
String Filename="e:\try\web-inf\classes\fxml.xml";
BufferedWriter fos;
System.out.println(backxml);
try {
fos = new BufferedWriter(new FileWriter((new File(Filename))));
fos.write(backxml);
fos.flush();
} catch(IOException e) {
System.out.println("写文档时发生io错误");
}
}
//数据库连接
public void openConnection() throws ClassNotFoundException,SQLException {
this.conn=DriverManager.getConnection( "jdbc:odbc:airwork;","sa","");
}
public void executequery(String query) throws SQLException {
this.stmt=conn.createStatement();
this.rset=stmt.executeQuery(query);
}
public void executeupdate(String query) throws SQLException {
this.stmt=conn.createStatement();
stmt.executeUpdate(query);
if (stmt!=null) stmt.close();
}
public void close() throws SQLException {
if (conn!=null) conn.close();
if (rset!=null) rset.close();
if (stmt!=null) stmt.close();
}
//开始XML解析
public void ParseDoc() throws ClassNotFoundException,SQLException
{
try
{
writexml();
openConnection();
DOMParser MyParser = new DOMParser();
MyParser.parse("e:\try\web-inf\classes\fxml.xml");
Document XMLDoc = MyParser.getDocument();
printNode(XMLDoc);
close();
}
catch (IOException e)
{
System.out.println("解析出错Error IOException!!!");
}
catch (SAXException e)
{
System.out.println("Error SAXException!!!");
}
}
public void printNode(Node node) throws ClassNotFoundException,SQLException
{
if (node.getNodeType() == Node.DOCUMENT_NODE)
{
System.out.println("DOCUMENT_NODE");
NodeList nodelist = node.getChildNodes();
if (nodelist != null)
{
for (int ii = 0; ii
请各位帮忙调试好吗?最好能加上注解。本人将十分感激。如果正确立即送分
package bean;
import java.io.*;
import java.net.*;
import java.util.*;
import java.sql.*;
public class Connectprice{
String backxml="";
ResultSet rset=null;
Connection conn =null;
Statement stmt =null;
String localname="",sql="";
String attribute="";
String flightNo="FlightNo",airline="";
String flightvalue="FlyDate",classes="";
String fromcity="FromCity";
String tocity="ToCity";
String startdate="DTime";
String enddate="";
//与服务器连接
public void sendxml(String xml){
Socket socket;
String len;
InputStream Is;
OutputStream Os;
DataInputStream DIS;
PrintStream PS;
try{
//向主机名为args[0]的服务器申请连接
//注意端口号要与服务器保持一致:1001
socket=new Socket("10.21.5.19",1001);
System.out.println("client ok");
System.out.println("************************************************");
System.out.println("");
//获得对应socket的输入/输出流
Is=socket.getInputStream();
Os=socket.getOutputStream();
//建立数据流
DIS=new DataInputStream(Is);
PS = new PrintStream(Os);
System.out.print("you say:"+xml);
PS.print(xml); //将读取得字符串传给server
System.out.println("");
System.out.println("please wait server`s message...");
System.out.println("");
backxml=DIS.readLine(); //从服务器获得字符串
System.out.println("server said:"+backxml); //打印字符串
//关闭连接
DIS.close(); //关闭数据输入流
PS.close(); //关闭数据输出流
Is.close(); //关闭输入流
Os.close(); //关闭输出流
socket.close(); //关闭socket
}
catch(Exception e){
System.out.println("连接Error:"+e);
}
}
//建立xml文档
public void writexml(){
String Filename="e:\try\web-inf\classes\fxml.xml";
BufferedWriter fos;
System.out.println(backxml);
try {
fos = new BufferedWriter(new FileWriter((new File(Filename))));
fos.write(backxml);
fos.flush();
} catch(IOException e) {
System.out.println("写文档时发生io错误");
}
}
//数据库连接
public void openConnection() throws ClassNotFoundException,SQLException {
this.conn=DriverManager.getConnection( "jdbc:odbc:airwork;","sa","");
}
public void executequery(String query) throws SQLException {
this.stmt=conn.createStatement();
this.rset=stmt.executeQuery(query);
}
public void executeupdate(String query) throws SQLException {
this.stmt=conn.createStatement();
stmt.executeUpdate(query);
if (stmt!=null) stmt.close();
}
public void close() throws SQLException {
if (conn!=null) conn.close();
if (rset!=null) rset.close();
if (stmt!=null) stmt.close();
}
//开始XML解析
public void ParseDoc() throws ClassNotFoundException,SQLException
{
try
{
writexml();
openConnection();
DOMParser MyParser = new DOMParser();
MyParser.parse("e:\try\web-inf\classes\fxml.xml");
Document XMLDoc = MyParser.getDocument();
printNode(XMLDoc);
close();
}
catch (IOException e)
{
System.out.println("解析出错Error IOException!!!");
}
catch (SAXException e)
{
System.out.println("Error SAXException!!!");
}
}
public void printNode(Node node) throws ClassNotFoundException,SQLException
{
if (node.getNodeType() == Node.DOCUMENT_NODE)
{
System.out.println("DOCUMENT_NODE");
NodeList nodelist = node.getChildNodes();
if (nodelist != null)
{
for (int ii = 0; ii