This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
RE: Jdbc Basics
Posted by uday on May 22, 2001 at 8:42 AM
Hi, Class.forName("...") is the starting point of your JDBC appn. To this function you've to pass the driver name which you are using to connect to database. It'll loads that driver into the DriverManager registry, & then when you call DriverManager.getConnection(..), it will return you the connection using the registered driver. sample code using Oracle thin driver is.. String driver = "oracle.jdbc.driver.OracleDriver"; String url = "jdbc:oralce:thin:@::"; Driver dr = (Driver) Class.forName( driver).newInstance(); DriverManager.registerDriver( dr ); Connection con=DriverManager.getConnection(url,user,paswd); Once u get the connection, you do executeQuery & all.. So, to compile this program you need to have the driver in the classpath. Else you'll get ClassNotFoundException; Since you are getting SQLException, data source not found you must be using JDBC-ODBC driver. So in that case you need to create a Data source name. Start->Settings->Control Panel->Data Sources->Add-> Select the driver->give username,password,server and so.... Its name should be same as that you are using in your appn. Hope it serves for the purpose -uday
> Sir, > I am Using Windows 98. When i Compile a Simple Jdbc Prog.Code, i get the Error " SQLException: Data Source Not Found and No Default Driver Specified" and I do not know how to fill the Parameter in: "Class.forName(....)" . > Pl help me..
Replies:
|