Todd,
When you create an array of reference types (objects), you must do two
steps. The first, you have done, is to create an instance of the array
object. The second step is to create the objects for each of the elements.
int i;
StringBuffer[] varSQLStatement = new StringBuffer[10]; // Step 1
for (i=9; i>=0; i--) {
varSQLStatement[i] = new StringBuffer(); // Step 2:added by me
varSQLStatement[i].append("INSERT INTO")
The first step creates an array of references each initialized to null.
>From your brief description of your problem, you should probably look into
using a prepared statement that you can execute with different parameters
instead of building strings.
This is one of Java's harder concepts and it gets more than just the
newbies. Hang in there.
Brian Dudley
Director, Consulting
CGI
-----Original Message-----
From: Todd Trent
To: JDJList
Sent: 5/10/02 3:38 PM
Subject: [jdjlist] StringBuffer array
Hi,
I'm a newbie looking for some help. How would I go about creating a
StringBuffer array?
I am trying to create 10 SQL statements with data collected from a JSP
form.
Each SQL statement is either an insert or update statement depending on
whether a record already exists in the database. I want to run through a
for
loop 10 times in order to append the field data to my StringBuffer
array.
<%
int i;
StringBuffer[] varSQLStatement = new StringBuffer[10];
for (i=9; i>=0; i--) {
varSQLStatement[i].append("INSERT INTO")
My code does compile, but I can't seem to get any data into the
StringBuffer
array.
<%=varSQLStatement[9]%> = null
Does anyone have any suggestions?...aside from looking for alternative
career. :-)
Thanks,
Todd
To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm
To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm