Dear All,

I didn't try to neither write the fasted program nor
the best looking code but the one with the least
number of lines.

Staying in the same logic below is the program with
the networking lines. Don't challenge me to add the
encryption part though :-)

import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.sql.*;

import java.io.*;
import java.net.*;

public class DBParser {

  public static void main(String args[]) {
    String url = "jdbc:odbc:SQLServer";
    String temp = new String();
    Connection con;
    Statement stmt;
    Element[] elem = new Element[10];
    int i = 0;

    try {
      DocumentBuilderFactory dbf = new
com.sun.xml.parser.DocumentBuilderFactoryImpl();
      DocumentBuilder db = dbf.newDocumentBuilder();
      Document outDoc = db.newDocument();
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      con = DriverManager.getConnection(url,
"myLogin", "myPassword");
      stmt = con.createStatement();
      ResultSet res = stmt.executeQuery("Select * from
Categories ");
      Element data = outDoc.createElement("Data");
      outDoc.appendChild(data);

      while (res.next()) {
        temp = res.getString("CategoryName");
        elem[i] = outDoc.createElement("CatName");
        elem[i].setAttribute("CategoryName", temp);
        data.appendChild(elem[i]);
        i++;
      }
      stmt.close();
      con.close();

      URL urlOut = new
URL("http://myTPhttpServer.com/cgi-bin/getXMLDoc.cgi");
        URLConnection connection =
urlOut.openConnection();
        connection.setDoOutput(true);
        PrintWriter outData = new
PrintWriter(connection.getOutputStream());
     
outData.println(outDoc.getElementsByTagName("Data").item(0).toString());
      outData.close();

      } catch(Throwable t) {
        System.err.println("Exception: " +
t.getMessage());
      }
  }
}

Again I apologise if the non-techies are annoyed.
Paul Aoun, Technical Manager

--- Brian Densmore <[EMAIL PROTECTED]> wrote:
> I actually thought it was a worthy entry. I do
> agree, on the networking
> portions. Both solutions so far are lacking the
> actual transmission phase.
> Wasn't that part of the approximate 10 lines? I
> prefer C myself, or better
> yet Python.
> 
> Brian Densmore
> Sr. Systems Analyst
> Computech Business Solutions
> 
> -----Original Message-----
> From: Marc Semanoff [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, July 27, 2000 10:34 AM
> To: 'kurt Svensson'; [EMAIL PROTECTED]; IT Man;
> Paul Williams;
> [EMAIL PROTECTED]
> Subject: RE: A FEW VERY SIMPLE QUESTION!!!
> 
> 
> First, you used multiple methods per line (bad
> coding practice). Second, 
> where is the JAVA code?
> 
> All in all:
> Interesting, but, where is the networking portion of
> your code?  You only 
> completed a small portion of the challenge.  Care to
> add some networking to 
> your entry and then see if your still at 10 lines?
> 
> 
> Marc Semanoff
> Defining Vision and Managing Change
> 
> 
> -----Original Message-----
> From: kurt Svensson [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, July 27, 2000 10:23 AM
> To:   [EMAIL PROTECTED]; IT Man; Paul Williams;
> [EMAIL PROTECTED]
> Subject:      Re: A FEW VERY SIMPLE QUESTION!!!
> 
> It could be done in 10 lines. See below
> implementation using our
> EDI language EDI-C.
> 
> main () {
> xmlelem CatName attlist (CategoryName);
> xmldoc Data {CatName; };
> EXEC SQL CONNECT TO :"database" USER :"someuser"
> USING :"somepassword";
> EXEC SQL DECLARE cur CURSOR FOR SELECT CategoryName
> FROM Categories;
> for (integer i = 1; SQLSTATE == "00000"; ++i)
>    EXEC SQL FETCH cur INTO
> :Data.CatName[i].#CategoryName;
> xmlwrite (Data, "somefile.xml");
> EXEC SQL DISCONNECT :"database";
> }
> 
> Regards
> 
> Kurt Svensson
> 
> www.inobiz.se
> 
> 
> 
> 
> 
> ------   XML/edi Group Discussion List   ------
> Homepage =  http://www.XMLedi-Group.org
> 
> Unsubscribe =  send email to:
> [EMAIL PROTECTED]
> Leave the subject and body of the message blank
> 
> Questions/requests:  [EMAIL PROTECTED]
> 
> To receive only one message per day (digest format)
> send the following message to [EMAIL PROTECTED],
> (leave the subject line blank)
> 
> digest xmledi-group your-email-address
> 
> To join the XML/edi Group complete the form located
> at:
> http://www.xmledi-group.org/xmledigroup/mail1.htm
> 
> 
> 
> 
> ------   XML/edi Group Discussion List   ------
> Homepage =  http://www.XMLedi-Group.org
> 
> Unsubscribe =  send email to:
> [EMAIL PROTECTED]
> Leave the subject and body of the message blank
> 
> Questions/requests:  [EMAIL PROTECTED]
> 
> To receive only one message per day (digest format) 
> send the following message to [EMAIL PROTECTED], 
> (leave the subject line blank) 
> 
> digest xmledi-group your-email-address
> 
> To join the XML/edi Group complete the form located
> at:
> http://www.xmledi-group.org/xmledigroup/mail1.htm
> 


__________________________________________________
Do You Yahoo!?
Kick off your party with Yahoo! Invites.
http://invites.yahoo.com/


------   XML/edi Group Discussion List   ------
Homepage =  http://www.XMLedi-Group.org

Unsubscribe =  send email to: [EMAIL PROTECTED]
Leave the subject and body of the message blank

Questions/requests:  [EMAIL PROTECTED]

To receive only one message per day (digest format) 
send the following message to [EMAIL PROTECTED], 
(leave the subject line blank) 

digest xmledi-group your-email-address

To join the XML/edi Group complete the form located at:
http://www.xmledi-group.org/xmledigroup/mail1.htm


Reply via email to