The Artima Developer Community
Sponsored Link

Java Answers Forum
jdbc.odbc.jdbcodbc error

2 replies on 1 page. Most recent reply: May 17, 2002 6:18 AM by Vikram.G.S.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Saravana Kumar . D

Posts: 1
Nickname: saravanak8
Registered: May, 2002

jdbc.odbc.jdbcodbc error Posted: May 17, 2002 12:39 AM
Reply to this message Reply
Advertisement
whenever in my code cntrl comes to

Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();

it gives out error,

below is my sample code
import java.sql.*;
//import sun.jdbc.odbc.*;
import java.util.*;

class sql1
{

public static void main(String args[]) throws ClassNotFoundException
{
String slno, ques, ans;
Connection con;
Statement stmt;
//ResultSet rs;

try
{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
java.sql.DriverManager.setLogStream(java.lang.System.out);


java.sql.Connection c = DriverManager.getConnection("jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=samp.mdb;PWD=mypass","user","pass");
java.sql.Statement st = c.createStatement();
java.sql.ResultSet rs = st.executeQuery("select * from samp");


//con=DriverManager.getConnection("jdbc:odbc:Wildtangent");
//stmt = con.createStatement();
//rs = stmt.executeQuery("SELECT * from samp");

while (rs.next())
{
slno=rs.getString(0);
ques=rs.getString(1);
ans=rs.getString(2);
System.out.println(slno);
System.out.println(ques);
System.out.println(ans);
}

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

}
}

please help me out


Rohit

Posts: 38
Nickname: rohit
Registered: May, 2002

Re: jdbc.odbc.jdbcodbc error Posted: May 17, 2002 12:52 AM
Reply to this message Reply
Make sure the jar/zip having this driver class file is in ur classpath

Vikram.G.S.

Posts: 16
Nickname: vidhi
Registered: Apr, 2002

Re: jdbc.odbc.jdbcodbc error Posted: May 17, 2002 6:18 AM
Reply to this message Reply
Please follow this code:

Statement s;
ResultSet rs;

try {
Class.forName("sun.jdbc.odbc.JdbcPdbcDrive")
Connection c=DriverManager.getConnection("jdbc:odbc:dsn");
Statement s=c.createStatement();
ResultSet rs=s.executeQuery("Select * from .......");
while(rs.next())
{
// your code goes here
}
}catch(Exception ex) { System.out.println(ex);}
finally {
c.close();
rs.close();
}

This will work. Please check it out.

Vikram

Flat View: This topic has 2 replies on 1 page
Topic: I always got exception:java.lang.NoClassDefFoundError: Previous Topic   Next Topic Topic: Is it because of Windows?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use