• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NEED HELP IN BASIC JDBC

 
Arul Jose
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main JDBC classes are in the java.sql package.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to JDBC...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic