Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Drew Dambrell
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try asking in the JDBC forum. Do you have any code yet?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Drew Dambrell
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
{
try{
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
Marshal
Pie
Posts: 64971
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
compatible!)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic