• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Class.forName()

 
Arun Maalik
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to the JDBC forum.
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic