• 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

NEED HELP IN BASIC JDBC

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wrote the following simple program to try jdbc for the first time.

class jdbctrial{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

String url = "jdbc dbc b";

Connection con = DriverManager.getConnection(url);

ResultSet rs;

Statement stmt = con.createStatement();

rs = stmt.executeQuery("select * from Table");

while(rs.next()){
System.out.println(rs.getString(1)+" "+rs.getInt(2)+" "+rs.getString(3));
}
stmt.close();
con.close();
}


i got the following error statements:

jdbctrial.java:2: <identifier> expected
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
^
jdbctrial.java:12: <identifier> expected
rs = stmt.executeQuery("select * from Table");
^
jdbctrial.java:14: illegal start of type
while(rs.next()){
^
jdbctrial.java:17: <identifier> expected
stmt.close();
^
jdbctrial.java:18: <identifier> expected
con.close();
^
5 errors

please help me out.

arul jose.
 
Arul Jose
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have found the problem.

i have not written the code within a method block.

now the next problem is, i dont know the packages that is should import!

need help.

jose.
 
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
The main JDBC classes are in the java.sql package.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to JDBC...
 
Whatever. Here's a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic