Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have problem to connect to my Database from my Java Code. I am using MS Access Database. I have created DSR Name and selected appropriate Database for my DSR Name.

DSR Name : connectionExample
Operating System : Windows 8 Pro (64 Bit).
Please answer me with full tutorial because I am a newbie.

My Java Code for Database Connection Example is :

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;


public class DatabaseConnection {


    public static void main(String[] args) {

                String uName="ABC",uPass="ABC",uEmail="ABC",uDate="ABC",uContactNo="ABC";
           try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                System.out.println("Driver Loaded");
                Connection con =  DriverManager.getConnection("Jdbc:odbc:connectionExample");
                Statement stmnt = con.createStatement();

                String sql = "insert into UserDetail values ('"+uName + "','"+uPass+"','"+uEmail+"','"+uDate+"','"+uContactNo+"')";
                int cnt = stmnt.executeUpdate(sql);
                   System.out.println("Database Updated.");     
                }
               catch (Exception ex) 
               {
                   System.out.println(ex);
               }
    }

}

The Output of my code is :

run:
java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
BUILD SUCCESSFUL (total time: 0 seconds)
share|improve this question
    
Jdbc-odbc bridge is deprecated in newest java releases –  Konstantin V. Salikhov Aug 2 at 17:55
    
what can I do now? –  Taran Boparai Aug 2 at 17:56
    
Use native jdbc driver like this one ucanaccess.sourceforge.net/site.html –  Konstantin V. Salikhov Aug 2 at 17:56
    
I am using Netbeans 8.0 for programming. I have done nothing manually. –  Taran Boparai Aug 2 at 17:57
    
hope it helps stackoverflow.com/questions/20469062/… –  Pat Aug 2 at 17:58

1 Answer 1

You must add connecter jar file to netbeans project library. Download jdbc connector jar file. Copy it to project folder select project in netbeans choose properties from right click menu. Select library->add jar file/folder select jdbc file. Now your code will work.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.