Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

jdbc error

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Following is the error I am getting when I compile the code below:
import java.sql.*;
class JdbcTest {
public static void main (String args []) throws SQLException {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc racle ci8:@lmtest", "gani", "babu");
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("select sname from students");
while (rset.next ())
System.out.println (rset.getString (1));
}
}
error
--------------------------
JdbcTest.java:5: Exception java.lang.ClassNotFoundException must be caught, or it must be declared in the throws clause of this method.
Class.forName("oracle.jdbc.driver.OracleDriver");

Pls help me if you have any suggestions.
Thanks
Gani
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ghani ,
when u throw an exception always remember to catch it ..i dont see a try catch block in u'r program.. the ideal program would be as below
class JdbcTest {
public static void main (String args []) throws SQLException
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DDriverManager.getConnection("jdbc racle:thin:username/password@host ort:sid");
Statement stmt = conn.createStatement ();
ResultSet rset = stmt.executeQuery ("select sname from students");
while (rset.next ())
{
System.out.println (rset.getString ("sname"));
}

}
catch(SQLException e)
{
}
}
guess this would work
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you are using Oracle Jdrivers instead of thin driver what would be the URL: ??? and the
Driver ClassName = ???
 
If a regular clown is funny, then a larger clown would be funnier. Math. Verified by this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic