Hi everybody!

I hope you can advise me how to accomplish the following task better:

In my servlet I communicate with Sybase DB through JConnect driver. But
once in a while I need to talk to
MS SQL Server DB, not often though.
My first question is:    what is more efficient - to use JDBC-ODBC
bridge or to execute a query through 'isql' application (as a Unix
command , using Runtime )  ?
I thought that JDBC-ODBC  would be too heavy-weight when you need to
execute couple of queries only,  so for now I try to execute them
through  the Unix command.    And here I've got the second question:
     I am able to execute the commands just fine, but the format of the
returned data is very difficult to deal with . I'll explain what I mean:

Here is how I execute a query  (I modified the Jason Hunter's example
...):

public class ExecQuery {
  private String query;

  public ExecQuery(String theQuery) {  query = theQuery; }

  public String toString(){
    StringBuffer out = new StringBuffer();
    String substr = "echo '" + query + "' > query.tmp; echo 'go' >>
query.tmp;" +
      " echo '' >> query.tmp";
    String [] command1 = { "/bin/csh", "-c", substr };
    String [] command2 = { "/bin/csh", "-c", "isql -Uuser -Ppassword
-Sserver < query.tmp"};

    Runtime runtime = Runtime.getRuntime();
    Process process = null;
    try {
      process = runtime.exec(command1);
      try {
             process.waitFor();
       } catch (InterruptedException e) { ...  }

      process = runtime.exec(command2);
      BufferedReader in = new BufferedReader (new InputStreamReader(
                          process.getInputStream() ) );
      String line = null;
      while (( line = in.readLine()) != null){
             out.append(line + "<BR>\n");
       }
    }
    catch (Exception e){  ...    }
    return out.toString();
  }
}

If I  pass  a query like this:   "select * from bundle where product_id
= 59"
then I get  a result like this:

product_id component h_status h_start_date
h_end_date
---------- --------- -------- --------------------------
--------------------------
53 63 PREV Jan 1 1986 12:00AM
Jul 24 1993 4:03PM
53 60 PREV Jan 1 1986 12:00AM
Jul 24 1993 4:03PM

  (2 rows affected)


which is pretty difficult to interpret - e.g.  to assign to some
variables, etc.
Is there any way to get rid of those header lines and to format the data
nicely?
The only way I can see, is to use some sed/awk script ,  but since there
can be any query, it's difficult to predict
the resulting data...
Did anybody try to do something like that?

thanks a lot,
Marina

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to