Forums Register Login
Need help Take out the null values from the ResultSet and Create a XML file
I am sorry i have to crosspost this but i need to solve this problem ASAP.
I would really appreicate if you can help me.
I wrote something which connects to Database and gets the ResultSet. From that ResultSet I am creating a XML file. IN my program these are the main two classes Frame1 and ResultSetToXML. ResultSetToXML which takes ResultSet & Boolean value in its constructor. I am passing the ResultSet and Boolean value from Frame1 class. I am passing the boolean value to get the null values from the ResultSet and then add those null values to XML File. When i run the program it works alright and adds the null and not null values to the file. But when i pass the boolean value to take out the null values it would not take it out and adds the null and not null values.
Please look at the code i am posing. I am showing step by step where its not adding the null values.
Any help is always appreciated.
Thanks in advance.
Frame1 Class
public class Frame1 extends JFrame{
private JPanel contentPane;
private XQuery xQuery1 = new XQuery();
private XYLayout xYLayout1 = new XYLayout();
public Document doc;
private JButton jButton2 = new JButton();
private Connection con;
private Statement stmt;
private ResultSetToXML rstx;
//Construct the frame
public Frame1() {
try {
catch(Exception e) {
//Component initialization
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
xQuery1.setUrl("jdbc dbc:SCANODBC");
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
xQuery1.setSql("Select * from Pinfo where pid=2 or pid=4");
jButton2.setText("Get XML from DB");

try {
catch(java.lang.ClassNotFoundException ex) {
System.err.print("ClassNotFoundException: ");
try {
con = DriverManager.getConnection("jdbc dbc:SCANODBC","SYSDBA", "masterkey");
stmt = con.createStatement();
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());

jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
contentPane.add(jButton2, new XYConstraints(126, 113, -1, -1));
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
void jButton2_actionPerformed(ActionEvent e) {
OutputStream out;
XMLOutputter outputter;
Element root;
org.jdom.Document doc;
root = new Element("PINFO");
String query = "SELECT * FROM PINFO WHERE PID=2 OR PID=4";
ResultSet rs = stmt.executeQuery(query);
/*===========This is where i am passing the ResultSet and boolean=======
===========value to either add the null or not null values in the file======*/
rstx = new ResultSetToXML(rs,true);
} //end of try
catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
ResultSetToXML class
public class ResultSetToXML {
private OutputStream out;
private Element root;
private XMLOutputter outputter;
private Document doc;
// Constructor
public ResultSetToXML(ResultSet rs, boolean checkifnull){
String tagname="";
String tagvalue="";
root = new Element("pinfo");
while (rs.next()){
Element users = new Element("Record");
for(int i=1;i<=rs.getMetaData().getColumnCount(); ++i){
tagname= rs.getMetaData().getColumnName(i);
/*============if the boolean value is false it adds the null and not
null value to the file =====================*/
/*============else it checks if the value is null or the length is
less than 0 and does the else clause in the if(checkifnull)===*/
if((tagvalue == null) || tagvalue.length() < 0 ){
users.addContent((new Element(tagname).setText(tagvalue)));
users.addContent((new Element(tagname).setText(tagvalue)));
users.addContent((new Element(tagname).setText(tagvalue)));
out=new FileOutputStream("c:/XMLFile.xml");
doc = new Document(root);
outputter = new XMLOutputter();
catch(IOException ioe){
catch(SQLException sqle){
Please don't post the same message in more than one forum. You obviously read more than one forum. The people who might answer your question do the same.
This thread is now closed. All replis to the one in XML
Paper beats rock. Scissors beats tiny ad.
Rocket Oven Kickstarter - from the trailboss

Reply locked
This thread has been viewed 797 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jul 19, 2018 05:56:26.