This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Starting to open the connection at the beginning of the class 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 "Starting to open the connection at the beginning of the class" Watch "Starting to open the connection at the beginning of the class" New topic
Author

Starting to open the connection at the beginning of the class

Nico Yukiko
Greenhorn

Joined: Aug 24, 2005
Posts: 21
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

Joined: Jan 10, 2002
Posts: 63208
    
  69

Basic Java. All executable statements must be within a method.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nico Yukiko
Greenhorn

Joined: Aug 24, 2005
Posts: 21
But how can i separate the code into a method and then call the method
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32481
    
214

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.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Nico Yukiko
Greenhorn

Joined: Aug 24, 2005
Posts: 21
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

Joined: Jul 14, 2005
Posts: 165
You may want to check out ArrayList.

LearnJDBC


Steve<br /> <br />No matter where you go, there you are.<br /> <br />"My evil self is at the door, and I have no power to stop it."
 
wood burning stoves
 
subject: Starting to open the connection at the beginning of the class
 
It's not a secret anymore!