Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0"

843810Apr 28 2004 — edited Apr 29 2004
I working on a program that will post information from our MSSQL Database to our website, but when I run it, it returns this error:
"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0"

I'm fairly new to Java, and I'm not quite sure I'm doing this correctly...any ideas? Thanks!

The command line parameters that I pass are:
/usr/java/j2sdk1.4.2_04/bin/java -cp /usr/jakarta-tomcat-4.1.30/websupport/support/WEB-INF/classes:/usr/java/j2sdkee1.4/lib/j2ee.jar:/usr/jakarta-tomcat-4.1.3
0/websupport/support/WEB-INF/lib/msbase.jar:/usr/jakarta-tomcat-4.1.30/websupport/support/WEB-INF/lib/mssqlserver.jar:/usr/jakarta-tomcat-4.1.30/websupport/su
pport/WEB-INF/lib/msutil.jar:/usr/jakarta-tomcat-4.1.30/websupport/support/WEB-INF/lib/jtds-0.7.1.jar com.curare.backend.postdocs

This is the program:

package com.curare.backend;


import java.sql.*;
import java.io.*;
import java.util.*;
import com.curare.backend.Connection;
import com.curare.sql.CurareConnection;

class postdocs
{
public static void main(String[] args)
{
postdocs used = new postdocs();
System.out.println(args[0]);
if(args.length==0) {
used.createWebPage("", "/var/www/html/");
}
else if(args.length==1) {
used.createWebPage(args[0], "/var/www/html/");
}
else {
used.createWebPage(args[0], args[1]);
}
}

public void createWebPage(String Filter, String path)
{

String temp;
String sql="";

String page = null;
int i;
boolean done = false;

FileReader fstream;
BufferedReader in;
PrintWriter out;
FileWriter temp_out;
FileWriter PWTxt_out;
PrintWriter PWout;

com.curare.backend.Connection conn = new com.curare.backend.Connection(CurareConnection.getDriver(), CurareConnection.getConnection());
ResultSet rs;
com.curare.backend.Connection conn2 = new com.curare.backend.Connection(CurareConnection.getDriver(), CurareConnection.getConnection());
ResultSet rs2;

try
{
///////
// Post Docs by Specialty
///////
sql = "select * from [Post Doc to Web]";
conn.open();
rs= conn.executeSql(sql);
while(rs.next()) {
page = rs.getString("WebPage").substring(Filter.length());
page = page.replaceAll("\\\\","/");
System.out.println(path + page + ".shtml");
fstream = new FileReader(path + page + ".shtml");
// Convert our input stream to a
// BufferedReader
in = new BufferedReader(fstream);
temp_out = new FileWriter(path + page + ".tmp");
out = new PrintWriter(temp_out);
// Continue to read lines while
// there are still some left to read
while ((temp = in.readLine()) != null && !(temp.startsWith("<!-- Begin Doctor Listing Code //-->")))
{
out.println(temp);
}
//Display Text to page
temp = "<p><b>" + rs.getString("Region") + "-</b>" + rs.getString("WebDescription") + "<br>";
if(!(rs.getString("FullName").equals(""))) {
temp += "<font color='#000099'>Physician # " + rs.getString("Physician Counter") + "</font> <b>Contact " + rs.getString("FullName") + " at " + rs.getString("WebTollFreeNumber") + "</b> or via <a href='mailto:info@physicianrecruiting.com?Subject=Web Response for Physician #" + rs.getString("Physician Counter") + "&body=Please insert your contact information in this email, as well as the best time to contact you.'>Email</a> or <a href='../submit-pos.shtml'>submit your info online</a> or via <a href='../contact.shtml'>Fax</a>.</p>";
}
out.println(temp);
while ((temp = in.readLine()) != null && !(temp.startsWith("<!-- End Doctor Listing Code //-->")))
out.println("<!-- End Doctor Listing Code //-->");
while ((temp = in.readLine()) != null)
{
out.println(temp);
}
in.close();
out.close();
}
conn.close();

/////////////
// Empty Pages
/////////////
sql = "select distinct WebSpecialtyClientSide.[WebPage] as WebPage from WebSpecialtyClientSide where not exists (select WebSpecialtyClientSide.[WebPage] from [Post Doc to Web] where WebSpecialtyClientSide.WebPage = [Post Doc to Web].WebPage ) and WebSpecialtyClientSide.WebPage is not null order by [WebSpecialtyClientSide].WebPage";
conn.open();
rs= conn.executeSql(sql);
while(rs.next()) {
page = rs.getString("WebPage").substring(Filter.length());
page = page.replaceAll("\\\\","/");
System.out.println(path + page + ".shtml");
fstream = new FileReader(path + page + ".shtml");
// Convert our input stream to a
// BufferedReader
in = new BufferedReader(fstream);
temp_out = new FileWriter(path + page + ".tmp");
out = new PrintWriter(temp_out);
// Continue to read lines while
// there are still some left to read
while ((temp = in.readLine()) != null && !(temp.startsWith("<!-- Begin Doctor Listing Code //-->")))
{
out.println(temp);
}
temp = "<p>Currently there are no physicians listed for this specialty. Please contact a consultant at (800) 880-2028 for the most current physicians or for a custom search. <a href='../submit-pos.shtml'>Click here to submit your contact information online</a></p>";
out.println(temp);
while ((temp = in.readLine()) != null && !(temp.startsWith("<!-- End Doctor Listing Code //-->")))
out.println("<!-- End Doctor Listing Code //-->");
while ((temp = in.readLine()) != null)
{
out.println(temp);
}
in.close();
out.close();
}
conn.close();
}
catch (Exception e)
{
System.err.println("File input error:"+e.getMessage() sql page);
}

}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 27 2004
Added on Apr 28 2004
2 comments
137 views