aspose file tools*
The moose likes JDBC and the fly likes Class.forName() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Class.forName()" Watch "Class.forName()" New topic
Author

Class.forName()

Arun Maalik
Ranch Hand

Joined: Oct 25, 2005
Posts: 216
import java.sql.*;
public class first{
public static void main(String[] args){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc.odbc.MyDataSource","sa","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("Select * from authors");
rs.beforeFirst();
while(rs.next()){
String id=rs.getString("au_id");
System.out.print(id);
}
rs.close();
}

catch(Exception e){
System.out.println(e);
}

}
}

Helo frnd In the above code it is throwing a exception that not sutable driver why ?

with regard

Arun
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Moving to the JDBC forum.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
Thers is nothing wrong in Class.forName(). Problem is at the time of connection.

At the time of connection, you need to provide three thing.. jdbc_url, username and password.



Your jdbc url is not correct. It should be "jdbcdbc:MyDataSource" instead of "jdbc.odbc.MyDataSource".


Naseem
[ July 13, 2006: Message edited by: Naseem Khan ]

Asking Smart Questions FAQ - How To Put Your Code In Code Tags
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Class.forName()