• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try asking in the JDBC forum. Do you have any code yet?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.....
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!)
reply
    Bookmark Topic Watch Topic
  • New Topic