0

I am a beginner in Java having only limited knowledge in SQL commands say 5 or 6 commands... I tried connecting my Java project with an access database "aman.accdb" using ODBC in my laptop.. The database has a table named "tab".. I am using a windows 7 64 bit pc with Java JDK for 64 bit installed in it. And also I use ms office 2013 which is also a 64 bit product.

When I executed the code an error " java.sql.SQLException No suitable drivers found for jdbc:odbc:man" I am posting the sample code which caused an error below. I have removed the unwanted lines such as layout setting and all as it runs for pages.

Please provide a solution to this!

package sample;

import java.sql.*;

import javax.swing.JOptionPane;

public class als extends javax.swing.JFrame {

    public als() throws SQLException {

        initComponents();

        try
        {
        con=DriverManager.getConnection("jdbc:odbc:man") ;
        }catch(Exception e)
        {
            JOptionPane.showMessageDialog(null, e);
        }
    }
    private void initComponents() {

        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton1.setText("Check");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });



    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        try
        {
          st=con.createStatement();
           String s=("insert into tab ('senthil',12)");
          st.execute(s);
             JOptionPane.showMessageDialog(rootPane,"Saved");
             this.setVisible(false);
            }catch(Exception e)
            {
                JOptionPane.showMessageDialog(rootPane,e);
            }
    }                                        


    static Connection con;
    static Statement st;
    static ResultSet rs;
    private javax.swing.JButton jButton1;                  
}

I came to know that this problem occurs in 64 bit OS oly.. Will this not happen if I install a 32 bit OS.

Note : The error I got is an exception which I displayed through a message box in catch() part in constructor als().

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Senthil Vidhiyakar
  • 182
  • 1
  • 2
  • 9

2 Answers2

2

I am using JDK 1.8.0

The JDBC-ODBC Bridge has been removed from Java 8. Consider using the UCanAccess JDBC driver instead. For details. see

Manipulating an Access database from Java without ODBC

Community
  • 1
  • 1
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
0

Try this, i believe its because you have not specified the driver. This is for MS Access database.

public als() throws SQLException {

    initComponents();

    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con=DriverManager.getConnection("jdbc:odbc:man") ;
    }catch(Exception e)
    {
        JOptionPane.showMessageDialog(null, e);
    }
}
Voqus
  • 159
  • 1
  • 11