Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP 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
Pie
Posts: 65115
89
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
Marshal
Posts: 34839
369
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic