Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: MS Access database connection problem

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Location
    Dhaka, Bangladesh
    Posts
    4
    My Mood
    Inspired
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default MS Access database connection problem

    Please help me to find out the problem with my code. I don't find exactly where the problem is. I am just trying to create a database connection and make a table. I am using MS Access.


    import java.sql.*;
    /**
     *
     * @author Faysal
     */
    public class dConnection {
     
        public dConnection() {
     
            try {
     
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.accdb)}; DBQ=Data.accdb;";
                Connection c = DriverManager.getConnection(database, "", "");
                Statement st = c.createStatement();
     
                String tName = "Student";
                String cTable = "CREATE TABLE " + tName +
                        "(id Integer, name Text(32), school Text(32), class Text(15), roll Text(10), "
                        + "phone Text(20), address(32))";
     
     
     
                st.execute(cTable);
     
     
                st.close();
                c.close();
            }
     
            catch(Exception e) {
     
                e.printStackTrace();
            }
        }
     
    }


  2. #2
    Junior Member
    Join Date
    Jul 2011
    Posts
    25
    My Mood
    Fine
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: MS Access database connection problem

    you have 2 errors
    * your driver is wrong
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
    Connection c=  DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D://Data.accdb;PWD=yourpassword;");
    * and you have Syntax error you didn't write type of address field

Similar Threads

  1. [SOLVED] I have a problem with this java code for database access
    By abhiM in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 19th, 2011, 03:52 AM
  2. Problem With Applet Connecting With Microsoft Access Database
    By Saurabh Mittal in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 29th, 2011, 10:43 AM
  3. [SOLVED] Connection to MySql Database
    By dego89 in forum JDBC & Databases
    Replies: 8
    Last Post: May 26th, 2011, 08:56 AM
  4. Database access..
    By _lithium_ in forum JDBC & Databases
    Replies: 7
    Last Post: March 2nd, 2011, 10:32 PM
  5. problems with connection to mysql database
    By thepower in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 20th, 2010, 02:59 AM