Originally posted by: znaps
What's the problem? Look through the ResultSet by doing:
Code:while (rs.next(){ Object o = rs.... // do something with o }
So you did something like:Originally posted by: CorporateRecreation
It will be a huge list I have to sort through, I want to match a last name in a database, if it exists, then ignore, if it doesn't then insert it.
Originally posted by: CorporateRecreation
Here is some pseudocode:
try{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection myCon = DriverManager.getConnection(edited out);
String query = "SELECT * FROM CUSTOMER WHERE CUSTLNAME ='" + name + "'";
statement = myCon.createStatement();
rs = statement.executeQuery(query);
while(rs.next())
{
db = rs.getString("custlname");
if(db.equals(name))
{
System.out.println("Already in database!");
}
//statement.close();
else
{
String query2 = "SELECT max(custID) from CUSTOMER";
statement2=myCon.createStatement();
rs2=statement.executeQuery(query2);
id = rs2.getString(1) + 1;
statement.executeUpdate("INSERT INTO Customers " +
"VALUES (id,custlname, custfname, address, zip)";
}
}
Originally posted by: kamper
Kilsrat's logic looks like what you want. You don't need a second Statement for the next query. I know you are only showing a quick example but in practice you should make a try/finally block immediately following the creation of any database related resource and close the resource in the finally block. Also, I don't know what your end use is but your method of establishing a connection is really only a possibility for a single user app that does not access the database very often. Anything with a chance of threading and concurrent database access should be using a connection pool and transactions.
Originally posted by: Koing
Originally posted by: kamper
Kilsrat's logic looks like what you want. You don't need a second Statement for the next query. I know you are only showing a quick example but in practice you should make a try/finally block immediately following the creation of any database related resource and close the resource in the finally block. Also, I don't know what your end use is but your method of establishing a connection is really only a possibility for a single user app that does not access the database very often. Anything with a chance of threading and concurrent database access should be using a connection pool and transactions.
Hey how wouldyou go about doing this then?
Just asking as I got to do a project and adding threading and concurrent db access would earn me more marks.
Thanks.
Koing
