question
[email protected] Fri, 8 Aug 2003 11:09:27 -0400
| Newsgroups | gmane.text.xml.sax.general |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I am trying to echo the contents of an XML file which is stored in a CLOB
field in an ORACLE database with the following code:
For some reason when I use the same code with a uri it works fine, when I
try to use it with an input stream I get nothing. Can someone point out
what I am doing wrong.
Any help would be greatly appreciated.
Regards,
Ritchie
Sample Code:
public class Class1 extends Object {
public static void main(String[] args) throws Exception {
Connection conn = null;
String SISuser = null;
String SIS_db_instance = null;
String SIS_db_user = null;
String SIS_db_pw = null;
SISuser = args[0];
SIS_db_instance = args[1];
SIS_db_user = args[2];
SIS_db_pw = args[3];
// load the Oracle JDBC driver
try
{
Class.forName( "oracle.jdbc.driver.OracleDriver" );
// Connect to the data base
String connection = "jdbc:oracle:thin:@saturn:1521:";
connection = connection + SIS_db_instance;
try {
conn = DriverManager.getConnection( connection, SIS_db_user,
SIS_db_pw );
}
catch( Exception e ) {
conn = null;
}
if( conn == null )
{
System.out.println ("uh ohhh");
}
// XML processing to follow:
Statement stmt = conn.createStatement();
String getIDs = "select scanned_files_id_seq, file_name from
scanned_files " +
" where file_type='XML'" +
" and processing_error is null";
ResultSet rs1 = stmt.executeQuery( getIDs );
int[] ids = new int[1500];
String[] prometric_xml_data_files = new String[1500];
int numIds = 0;
System.out.println("here1");
while( rs1.next() )
{
ids[numIds] = rs1.getInt(1);
prometric_xml_data_files[numIds] = rs1.getString(2);
numIds++;
}
rs1.close();
System.out.println("here2");
for( int j=0; j < numIds; j++ )
{
int current_scanned_id = ids[j];
String current_prometric_file = prometric_xml_data_files[j];
String getClob = "select text from scanned_files " +
" where scanned_files_id_seq = " +
Integer.toString( ids[j] );
ResultSet rs2 = stmt.executeQuery( getClob );
System.out.println("here3");
int count = 0;
if( rs2.next() )
{
count++;
CLOB clob_loc = (CLOB)rs2.getObject(1);
InputStream inStream = ((CLOB)clob_loc).getAsciiStream();
System.out.println("here4");
// Use an instance of DefaultHandler as the SAX event handler
DefaultHandler handler = new DefaultHandler();
SAXParserFactory factory = SAXParserFactory.newInstance();
try{
System.out.println("here5");
// Parse the input
SAXParser saxParser = factory.newSAXParser();
saxParser.parse( new DataInputStream(inStream), handler);
System.out.println("here6");
}
catch (SAXParseException spe) {
// Error generated by the parser
System.out.println("\n** Parsing error"
+ ", line " + spe.getLineNumber()
+ ", uri " + spe.getSystemId());
System.out.println(" " + spe.getMessage() );
// Use the contained exception, if any
Exception x = spe;
if (spe.getException() != null)
x = spe.getException();
x.printStackTrace();
} catch (SAXException sxe) {
// Error generated by this application
// (or a parser-initialization error)
Exception x = sxe;
if (sxe.getException() != null)
x = sxe.getException();
x.printStackTrace();
} catch (ParserConfigurationException pce) {
// Parser with specified options can't be built
pce.printStackTrace();
} catch (IOException ioe) {
// I/O error
ioe.printStackTrace();
}
} // end if
} // end for
} // end main try block
catch (Exception e){
System.out.println("didn't work");
System.out.println(e);
conn.close();
conn = null;
return; }
finally
{
conn.close();
conn = null;
System.out.println("cleanup done");
}
} // end main
-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
List: [email protected]
See: http://www.saxproject.org
https://lists.sourceforge.net/lists/listinfo/sax-users