Win a copy of Head First Android this week in the Android forum!

Allen Thomas

Greenhorn
+ Follow
since Jul 02, 2002
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Allen Thomas

Yes, it does help. Thank you.
18 years ago
I was looking through some code of my friends and he has this in his program:
//rst is the RecordSet
...
while(rst.next()) {
String tempId = rst.getString("var1");
String tempCd = rst.getString("var2");
//5 other Strings in this loop
}
I had told him that this is not efficient because of the string object in the loop. Am I right? He disagrees with me. Would anyone have a better explanation in why do or not do this type of programming?
Thanks in advance!
18 years ago
Hi, I am pulling my hair with such great frustration with this problem I having and I hope someone here could shed some light upon me.
I am using jdbc-odbc bridge connecting to an access database. In this database, I have a table which has to fields, id and pid. I don't have a primary key, which is probably our problem, but nonetheless...problem should not exist.
Anyways... the values I have in there are:
id pid equipment
12128 10859
12128 10859 screwdriver

this is my query...
selectQry = "SELECT id, pid FROM MasterMapping WHERE (pid IS NOT NULL) AND (equipment IS NOT NULL) ORDER BY id;";
ResultSet rst = db.queryData(selectQry);
if (rst != null){
while(rst.next()){
int IdKey = rst.getInt("id");
int pid = rst.getInt("pid");
System.out.println("ID: " + IdKey + " PID: " + pid);
}
rst.close();
}
...
...
I am expecting the output:
ID: 12128 PID: 10859
but I get this:
ID: 12128 PID: 10860
The PID increased by one. I have no idea anymore how I could get what is in the database which is the PID 10859
Any help is appreciated. Thank you in advance.
Allen
Hi
I am using batch updating (i.e. stmt.addBatch(sqlString), executeBatch(), etc.)
my code is:
int id = 0;
String sqlStr = "";
...
...
//createNewStatement is a customize method for creating a new statement.
Statement insertStmt = db.createNewStatement();
while(!(idVector.isEmpty())){
id = idVector.firstElement();
sqlStr = "INSERT INTO ids VALUES ('" + id + "')";
insertStmt.addBatch(sqlStr);

}
...
insertStmt.executeBatch();
insertStmt.close();
...
My question is: if somehow the id had a problem when it is executing the batch, how could I output the id that had the problem and continue on processing the others after it? Is there someway in retreiving the error from the executeBatch? I have tried putting it in a try-catch block, it doesn't work. I tried this:
try{
//execute batch
}catch(BatchUpdateException b){
System.err.println("SQLException: " + b.getMessage());
System.err.println("SQLState: " + b.getSQLState());
System.err.println("Message: " + b.getMessage());
}
and all it does is give me a "General Error" message.
Any help would be greatly appreciated. Thank you.
Allen
It just
I am thinking about using Batch updates (i.e. stmt.executeBatch() ) but I am not quite understanding the advantages. I read in http://java.sun.com/docs/books/tutorial/jdbc/jdbc2dot0/batchupdates.html that " ... Sending multiple update statements to the database together as a unit can, in some situations, be much more efficient than sending each update statement separately.
My question(s) is: What do they mean "...in some situations..." batch updates would be efficient? Is there an example of where it would not be efficient to use it?
I am using the standard JDBC-ODBC driver connecting to an access database. Did anyone have any problems that I will encounter?
Thanks for your help in advance.
Allen
Here is the link that says to use Strings as the keys: (Slide 15)
www.cis.upenn.edu/~matuszek/cit594-2002/ Slides/using-maps.ppt
Here is the link that says Integers are better performing
saloon.javaranch.com/34/002109.html posted by ranch hand Steve Deadsea, but I think he is talking about HashTable. Same concept?
Thanks
19 years ago
I read somewhere that String objects oppose to Integer Objects are far better to use as the key for HashMap because strings are immutable. On the other hand, a recent post by someone on here, said that Integer Objects are better than String Objects to use as keys because they are efficient when searching.
Could anyone explain to me which is better to use?
Thank you in advance.
Allen
19 years ago
Thanks Chris for your help! It worked. I don't know what I was thinking or not thinking. =)
I'm sorry...what did you mean by "does not propagate the exception"?
Thanks
Allen
[ October 17, 2002: Message edited by: Allen Thomas ]
Great Thanks.
Would any of the two or anyone know how to capture the exception when a illegal value is trying to be inserted (using the PreparedStatement executeUpdate() )into a table?
For example:
try{
String murInsertQry = "INSERT INTO table (id, iDdesc, idtype) VALUES (?,?,?)";
PreparedStatement preparedStmt = db.prepareStatement(murInsertQry);
while(!(myVector.isEmpty())){
preparedStmt.setInt(1, id);
preparedStmt.setString(2, idDesc);
preparedStmt.setInt(3, idType);
int test = preparedStmt.executeUpdate();
}
}catch(Exception e){
e.printStackTrace();
}
The problem is that I could process most of my data and insert them in but when I run into a illegal value such as duplicate id's, I get an exception and the program terminates the loop without process the other records. How would I know to capture the exception and still continue through the loop and insert? That is why I created the int test variable but at that point it is too late. Thanks in advance for any suggestions.
Allen
Hi everyone,
Would anyone know if MS Access supports PreparedStatements?
Thanks.
Thanks so much. I have been given the right steps into finding a solution.
19 years ago
Hi,
Does anyone know of a way to include the method name in which the exception was thrown, instead of hard coding the name?
for example:
public void exceptionMethod(){
try{
...
}catch(Exception e){
System.out.println("Exception in exceptionMethod: " + e);
}
}
Thanks
19 years ago
Hi everyone,
I am storing most of my resultsets in a vector because I do not want to access my database x-amount times. My question is, when creating vectors, would it be in-efficient to create a lot of vectors?
Thanks in advance,
Gregg
19 years ago
Hi,
I found this url: http://mindprod.com/classpath.html
very helpful in my understanding of classpaths. I hope it helps you.
Allen
19 years ago