2

A program to retrive records from database

       import java.sql.*;
       import javax.sql.*;

public class Database 
{
    public static void main(String a\[\])
    {
        try
        {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection cn =DriverManager.getConnection("jdbc:odbc:data");
        Statement st=cn.createStatement();
        ResultSet rs= st.executeQuery("select * from student ");
        while(rs.next())
        {
            int r=rs.getInt(1);
            String n= rs.getString(2);
            int m=rs.getInt(3);
            System.out.println("Roll Name Marks");
            System.out.println(r+" "+n+" "+m);
        }
        cn.close();
        }
        catch(Exception e)
        {
        }
    }
}][1]

I am running 64 bit Windows 7 Created the DSN from sysWOW64 folder Have a database consisting of 3 fields Roll Name Mark After Compiling no errors are found Executing the program results in no Output Why I am not able to Execute the program

![At command line no output][1]

Edit from comments

The exception I am getting is

SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
Nik6019
  • 59
  • 5
  • use e.printStackTrace() in catch block, to see if any exception. – Rahul Feb 24 '14 at 13:56
  • You are probably getting an exception at runtime but you cannot see it because of empty `catch` block. You must be sure Java, DSN and MS ODBC driver are all the same architecture either 32 or 64 bits. Otherwise you'll get compatibility issues. – dic19 Feb 24 '14 at 13:58
  • this was the out put java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contai ns an architecture mismatch between the Driver and Application – Nik6019 Feb 24 '14 at 13:59
  • 1
    That's what I'm talking about. Your Java architecture probably is 64 bits but accessing DSN through sysWOW64 is the 32 bits ODBC controller (if I remember right). Consequently you have architecture mismatch issues. – dic19 Feb 24 '14 at 14:02
  • So what solution is required – Nik6019 Feb 24 '14 at 14:04

2 Answers2

1

Based on this error:

java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contai ns an architecture mismatch between the Driver and Application

The problem is your Java architecture is probably 64-bits based but when you accessOdbcad32.exe through this path:

%windir%\SysWoW64\odbcad32.exe

You're actually accessing the 32-bits version of the ODBC controller. Consequently you have architecture mismatch issues. Check this answer for more details.

To make it work you must be sure Java, DSN and MS ODBC driver are all the same architecture either 32 or 64 bits.

So you can:

  • Download a 32-bits JDK and leave the DSN you already have.
  • Access the DSN directly from %windir%\System32 folder (is the 64-bits version) and create the data source there.
Community
  • 1
  • 1
dic19
  • 17,821
  • 6
  • 40
  • 69
  • Should i get office 64 bit or jdk 32 bit...(jdk is 64 bit) – Nik6019 Feb 24 '14 at 14:14
  • Exactly. I had the same issue before because my Office was 32-bits. I've downloaded jdk 32 bits and accessed DSN through the same path as you do. Then all was 32-bits based and it worked like a charm. @user3346898 – dic19 Feb 24 '14 at 14:17
  • thanks everything working like a charm – Nik6019 Feb 24 '14 at 14:30
-2

When you receive no Java exception/error and no output, it seems you can connect to the database and it simply doesn't contain any data.

Smutje
  • 17,733
  • 4
  • 24
  • 41