Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes JDBC and Relational Databases and the fly likes Argh.....he'p....He'p I sez(plz) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Argh.....he Watch "Argh.....he New topic

Argh.....he'p....He'p I sez(plz)

Drew Dambrell

Joined: Mar 31, 2004
Posts: 6
I was in need of some Info...(my first post btw)...I am trying to pass values from an ArrayList into individual fields in a Database, I have no clue what I'm doing.....any help in the way of this would be awesome, thx guys

Pimpin tha code, one servlet @ a time
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1170

try asking in the JDBC forum. Do you have any code yet?
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Mr. (),
Welcome to JavaRanch! We don't have too many rules 'round here, but we do have a naming policuy, which basically asks you to use your real first and last name, or at least something that isn't so obviously fake. Please head over here and fix your display name, pronto!
I'm going to help you out by moving this question to the JDBC forum. Followups there, please.

[Jess in Action][AskingGoodQuestions]
Drew Dambrell

Joined: Mar 31, 2004
Posts: 6
These are some snippets of code that explains what I'm talking about:
(Prepared Statement)
AddACategory2 = connection.prepareStatement("INSERT INTO TABLE tbl_CategoryOptions (SKU, Category, Size, Color) VALUES (?), (?), (?), (?)");

(Method using Prep Statement)
private void AddCategory(int a, ArrayList b)
AddACategory1.setInt(1, a);
AddACategory2.setInt(1, ???);

catch(SQLException se){ se.printStackTrace();}
I'm pulling in an Int and 3 Strings sequentially from ArrayList b and I need to place them into AddACategory2.....
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

Drew, three things:
1) Please remove the trailing stuff from your display name, "Drew Dambrell" will do nicely. Thanks.
2) The syntax of the values clause should be values (?,?,?,?)
3) Without knowing what AddACategory2 is, I'm not sure how to answer your question. Given its naming convention, I'd say it's a class name and setInt is a static method. Or is it a badly named variable for a PreparedStatement?
Is it iterating through the array list that you're confused about? Not sure exactly where your issues lie.

[Asking smart questions] [About Bear] [Books by Bear]
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
This might help get you started:

It's a little hard to tell if this will satisfy your request, since you indicate that the SKU (int) and other values (String) all come from an ArrayList, but in the method you show that the int values is being passed in separately from the ArrayList.
If the int value is being passed in via the ArrayList, it must either be coming across as a String (i.e., "123"), or an Integer (i.e., new Integer(123)).
Also, does the ArrayList contain information for only one entry, or does it contain multiple sets? If you have multiple sets, you'll need some sort of a "for" loop to process them all.
In either case, what I've given should help you get started. Whatever you put into an ArrayList will come out as an "Object" instance, and so much be cast to appropriate data type.
When setting the parameters of a PreparedStatement, the column values are 1-based, but the ArrayList indexes are 0-based.
[ March 31, 2004: Message edited by: Wayne L Johnson ]
Drew Dambrell

Joined: Mar 31, 2004
Posts: 6
Thanks guys for all your input, you've been a great help to me, I definitely know where I'm e-chillin from now on
p.s.(yay for puttin e- in front of everything to make it internet
I agree. Here's the link:
subject: Argh.....he'p....He'p I sez(plz)
It's not a secret anymore!