当前位置: 技术问答>java相关
求求你们了,帮帮忙。分全给你们了。急啊?
来源: 互联网 发布时间:2015-09-09
本文导语: 我想把数据库中的记录取出来,然后新建一xml文件,将数据存入,用于以后的数据交换。 用记事本编辑,然后在jdk下用javac,java都可运行。 可我把这文件原封不动的建立到jbuilder7下。编译无错误,可运行后建立的却...
我想把数据库中的记录取出来,然后新建一xml文件,将数据存入,用于以后的数据交换。
用记事本编辑,然后在jdk下用javac,java都可运行。
可我把这文件原封不动的建立到jbuilder7下。编译无错误,可运行后建立的却是空文件。
为何啊?同样的文件,换个地方就不好使了????
源代码如下:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.PreparedStatement;
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.io.*;
//Á¬½ÓjdsÊý¾Ý¿â
import com.borland.dx.sql.dataset.*;
import com.borland.dbswing.*;
import com.borland.dx.dataset.*;
public class Pricing extends Object {
public static void main (String args[]){
//Create the Document object
Document mapDoc = null;
//Define a new Document object
Document dataDoc = null;
//Create the new Document
Document newDoc = null;
try {
//Create the DocumentBuilderFactory
DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
//Create the DocumentBuilder
DocumentBuilder docbuilder = dbfactory.newDocumentBuilder();
//Parse the file to create the Document
//mapDoc = docbuilder.parse("mapping.xml");
//Instantiate a new Document object
dataDoc = docbuilder.newDocument();
//Instantiate the new Document
newDoc = docbuilder.newDocument();
} catch (Exception e) {
System.out.println("Problem creating document: "+e.getMessage());
}
Database database1 = new Database();
Statement statement=null;
String sql="";
//Create the ResultSetMetaData object, which will hold information about
//the ResultSet
ResultSetMetaData resultmetadata = null;
//Create a new element called "data"
Element dataRoot = dataDoc.createElement("data");
try {
// Class.forName(driverName);
//db = DriverManager.getConnection(connectURL,"sa","9755");
database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:borland:dslocal:D:\JBuilder6\bin\market.jds", "sample", "", false, "com.borland.datastore.jdbc.DataStoreDriver"));
} catch (Exception e) {
System.out.println("Error creating connection: "+e.getMessage());
}
//Create the Statement object, used to execute the SQL statement
//PreparedStatement statement = null;
//Create the ResultSet object, which ultimately holds the data retreived
ResultSet resultset = null;
sql="select "company_id","variety_id","yc_balance","by_income","lj_income","by_bsqk","lj_bsqk","by_xshk","lj_xshk","ym_balance","product_prop" from "financial_report" where "id" in(8,1,7,6,0,2)";
System.out.println(sql);
try {
statement =database1.createStatement();
resultset=statement.executeQuery(sql);
// statement = db.prepareStatement("select * from products");
//Execute the query to populate the ResultSet
//resultset = statement.executeQuery();
//Get the ResultSet information
resultmetadata = resultset.getMetaData();
//Determine the number of columns in the ResultSet
int numCols = resultmetadata.getColumnCount();
//System.out.println(numCols);
//Check for data by moving the cursor to the first record (if there is one)
while (resultset.next()) {
//System.out.println(resultset.getString("company_id"));
//For each row of data
//Create a new element called "row"
Element rowEl = dataDoc.createElement("row");
for (int i=1; i
用记事本编辑,然后在jdk下用javac,java都可运行。
可我把这文件原封不动的建立到jbuilder7下。编译无错误,可运行后建立的却是空文件。
为何啊?同样的文件,换个地方就不好使了????
源代码如下:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.PreparedStatement;
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.io.*;
//Á¬½ÓjdsÊý¾Ý¿â
import com.borland.dx.sql.dataset.*;
import com.borland.dbswing.*;
import com.borland.dx.dataset.*;
public class Pricing extends Object {
public static void main (String args[]){
//Create the Document object
Document mapDoc = null;
//Define a new Document object
Document dataDoc = null;
//Create the new Document
Document newDoc = null;
try {
//Create the DocumentBuilderFactory
DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
//Create the DocumentBuilder
DocumentBuilder docbuilder = dbfactory.newDocumentBuilder();
//Parse the file to create the Document
//mapDoc = docbuilder.parse("mapping.xml");
//Instantiate a new Document object
dataDoc = docbuilder.newDocument();
//Instantiate the new Document
newDoc = docbuilder.newDocument();
} catch (Exception e) {
System.out.println("Problem creating document: "+e.getMessage());
}
Database database1 = new Database();
Statement statement=null;
String sql="";
//Create the ResultSetMetaData object, which will hold information about
//the ResultSet
ResultSetMetaData resultmetadata = null;
//Create a new element called "data"
Element dataRoot = dataDoc.createElement("data");
try {
// Class.forName(driverName);
//db = DriverManager.getConnection(connectURL,"sa","9755");
database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:borland:dslocal:D:\JBuilder6\bin\market.jds", "sample", "", false, "com.borland.datastore.jdbc.DataStoreDriver"));
} catch (Exception e) {
System.out.println("Error creating connection: "+e.getMessage());
}
//Create the Statement object, used to execute the SQL statement
//PreparedStatement statement = null;
//Create the ResultSet object, which ultimately holds the data retreived
ResultSet resultset = null;
sql="select "company_id","variety_id","yc_balance","by_income","lj_income","by_bsqk","lj_bsqk","by_xshk","lj_xshk","ym_balance","product_prop" from "financial_report" where "id" in(8,1,7,6,0,2)";
System.out.println(sql);
try {
statement =database1.createStatement();
resultset=statement.executeQuery(sql);
// statement = db.prepareStatement("select * from products");
//Execute the query to populate the ResultSet
//resultset = statement.executeQuery();
//Get the ResultSet information
resultmetadata = resultset.getMetaData();
//Determine the number of columns in the ResultSet
int numCols = resultmetadata.getColumnCount();
//System.out.println(numCols);
//Check for data by moving the cursor to the first record (if there is one)
while (resultset.next()) {
//System.out.println(resultset.getString("company_id"));
//For each row of data
//Create a new element called "row"
Element rowEl = dataDoc.createElement("row");
for (int i=1; i