Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with MS Access using Microsoft SDK

 
hasan wasif2k1
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Program written below gives error with Microsoft SDK when connecting MS Access but working perfectly when using Sun JDK.
Error it gives is :- java.lang.NoClassDefFoundError
Using same code for Microsoft SDK and Sun SDK
customer: DSN Name
class test
{
public static void main(String args[])
{
Connection c=null;
Statement st=null;
ResultSet rs=null;
try
{
// For Connecting with MS-Access
System.out.println("1111");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
System.out.println("222");
c=DriverManager.getConnection("jdbc dbc:customer");
System.out.println("333");
st=c.createStatement();
String query="select count(*) as count from rainbowcustomers";
rs=st.executeQuery(query);
while(rs.next())
{
int count=rs.getInt("count");
System.out.println(count);
}
}
catch(NoClassDefFoundError e)
{
System.out.println(e);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Gives error after printing 111 222. This means error is at
c=DriverManager.getConnection("jdbc dbc:customer");
Couldn't solve it. Pls somebody help.
Thanks
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

while(rs.next())
{
int count=rs.getInt("count");
System.out.println(count);
}

sometimes even though you rename the column to count, the driver cannot see this. Try changing the column name "count" to absolute position 1 in the getInt() method:

while(rs.next())
{
int count=rs.getInt(1);
System.out.println(count);
}

Jamie
 
hasan wasif2k1
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But the program doesn't even reach there as it does not print 333
which is after
c=DriverManager.getConnection("jdbc dbc:customer");
System.out.println("333");
The problem is only at
c=DriverManager.getConnection("jdbc dbc:customer");
and that too working perfectly with Sun SDK but not when executing in VJ++ or Microsoft SDK ???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic