Inserting 23000 records

[nobr]I was wondering if there was a better way to do this than i'm doing here is my code:

String strSQL ="";

while(objDBFReader.hasNextRecord())

{

Object[] objRecords = objDBFReader.nextRecord();

if(!containsString(strProvinces, objRecords[0].toString()))

strProvinces.add(objRecords[0].toString());

if(!containsString(strYears, objRecords[2].toString()))

strYears.add(objRecords[2].toString());

try

{

strSQL ="INSERT INTO CROP_CENSUS30 VALUES('";

strSQL += objRecords[0]+"' ,"+objRecords[1]+", ";

strSQL += objRecords[2]+", '"+objRecords[3]+"', ";

for(int x = 4; x < objRecords.length; x++)

{

if(objRecords[x] !=null && !objRecords[x].toString().equals(""))

strSQL +=objRecords[x]+" ,";

else

strSQL +="'' ,";

}

strSQL=strSQL.substring(0,strSQL.length()-2);

strSQL +=")";

objStatement.addBatch(strSQL);

}

catch(Exception e2)

{

out.println("<fieldset>Error Processing Record:"+intRecords+"<br/> Error Message: "+e2.getMessage()+"<br /> SQL Statement: <br/>"+strSQL+"</fieldset>");

}

intRecords++;

}

objDBFReader.close();

objDBFReader =null;

out.println("Inserting "+intRecords+" into CROP_CENSUS30 ...");

out.flush();

objStatement.executeBatch();

[/nobr]

[2401 byte] By [ZimmerS1337a] at [2007-11-27 8:35:30]
# 1
> I was wondering if there was a better way to do thisUse the import tools that come with the database and don't use java at all.
jschella at 2007-7-12 20:32:08 > top of Java-index,Java Essentials,Java Programming...
# 2
But if you are going to use Java then please use PreparedStatements and batch your inserts.That alone will for a variety of reasons make your code generally better, certainly safer, and I would bet faster.
cotton.ma at 2007-7-12 20:32:08 > top of Java-index,Java Essentials,Java Programming...
# 3
Well, for one thing, you should use PreparedStatement and its ? parameters, rather than building SQL string literals, dates, etc. yourself.Other than that, does it work?
jverda at 2007-7-12 20:32:08 > top of Java-index,Java Essentials,Java Programming...
# 4

That is not possible, the end user is generating dbf files from a gui app and they arnt tech savy. They are uploading the dbf and then a bunch of records get inserted, then a bunch of calculations are performed in PL/SQL (would have been done in java but they already exist so we are leaving them in there) and then returning a results dbf.

ZimmerS1337a at 2007-7-12 20:32:08 > top of Java-index,Java Essentials,Java Programming...
# 5
Check out this sexy article written by some smart guy http://www.sdnshare.com/view.jsp?id=525
cotton.ma at 2007-7-12 20:32:08 > top of Java-index,Java Essentials,Java Programming...
# 6
The script works, i've just come to a recent relization that alot of my code would be considered hacks by guru's. So i'm trying to improve. Thanks for the info guys :)
ZimmerS1337a at 2007-7-12 20:32:08 > top of Java-index,Java Essentials,Java Programming...
# 7

> That is not possible, the end user is generating dbf

> files from a gui app and they arnt tech savy. They

> are uploading the dbf and then a bunch of records get

> inserted, then a bunch of calculations are performed

> in PL/SQL (would have been done in java but they

> already exist so we are leaving them in there) and

> then returning a results dbf.

So use jave to run the import tool.

And why do you think that the calcs would have been better done in java versus SQL?

By the way you are keeping the results in the database right? Not doing so means that the calculations can't change or at least not if you want to repeat reports or explain report results.

jschella at 2007-7-12 20:32:08 > top of Java-index,Java Essentials,Java Programming...