Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Starting to open the connection at the beginning of the class

 
Nico Yukiko
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How come i can't place the try at the start of a new class and the code below is giving me a problem.and regarding declaring an array to store the info in the database to replace the static code at the bottom is also giving problem.



[edited to add code tags]
[ August 24, 2005: Message edited by: Jeanne Boyarsky ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65658
129
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basic Java. All executable statements must be within a method.
 
Nico Yukiko
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But how can i separate the code into a method and then call the method
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 35977
422
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nico,
Welcome to JavaRanch!

I'm guessing you want to run this as a standalone program. In that case, add the line:

before the first "try {". And then close the brace with a } at the end of the code.

To call it, you can then do "java Catalog" from the command line.
 
Nico Yukiko
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But how can i store the information retrieve from the database into an array so that i can create a new catalog item base on the array
 
Stephen Boston
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may want to check out ArrayList.

LearnJDBC
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!