Connecting a Microsoft Access Database to Java using JDBC and compiling

Posted on Nov 30, 2010 8:11 AM, Ms-access - Stack Overflow | stackoverflow.com

for a school database project we are making a database program (user GUI and the database). Using Microsoft Access 2010 I created the database and populated it with some sample data, and saved it in .mdb format and placed it in my project folder.

When running it in eclipse the following code works fine, connects and even retrieves the query. However I find that I am unable to export the code to a jar and run it (which is required for the project, give them a working copy of your program on a CD or flash drive), and I'm also unable to port the code over to Netbeans to have it work, as well as trying to compile on a Linux machine.

I assume this is a problem with including drivers or trying to use Microsoft access. The error I get when running the jar or running on Netbeans is given below the code. So I ask either how do I include drivers to make the program portable, or how else can I approach this problem?

Thanks in advance

import java.sql.*;

public class JDBCTest {
    static Connection connection;
    static Statement statement;

    public static void main(String args[]){

        try {
            Class.forName('sun.jdbc.odbc.JdbcOdbcDriver').newInstance();
            String database = 'jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=TLDATABASEDBM.mdb';
            connection = DriverManager.getConnection( database ,'',''); 

            buildStatement();
            executeQuery();

        }catch(Exception e){
            e.printStackTrace();
            System.out.println('Error!');
        }
    }

    public static void buildStatement() throws SQLException {
        statement = connection.createStatement();
    }

    public static void executeQuery() throws SQLException {

        boolean foundResults = statement.execute('SELECT * FROM tblStaff  AS x WHERE City='Calgary'');
        if(foundResults){
            ResultSet set = statement.getResultSet();
            if(set!=null) displayResults(set);
        }else {
            connection.close();
        }
    }

    public static void displayResults(ResultSet rs) throws SQLException {
        ResultSetMetaData metaData = rs.getMetaData();
        int columns=metaData.getColumnCount();
        String text='';

        while(rs.next()){
            for(int i=1;i<=columns;++i) {
                text+=''+metaData.getColumnName(i)+':\t';
                text+=rs.getString(i);
                //text+='</'+metaData.getColumnName(i)+'>';
                text+='\n';
            }
            text+='\n';
        }

        System.out.println(text);

    }
}

The error mentioned above:

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
        at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
        at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
        at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3073)
        at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
        at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
        at java.sql.DriverManager.getConnection(DriverManager.java:582)
        at java.sql.DriverManager.getConnection(DriverManager.java:207)
        at tldatabase.DataConnect.makeConnection(DataConnect.java:35)
        at tldatabase.Main.main(Main.java:24)

Similar Messages
  1. How to access microsoft access database (1997) in java
  2. How to connect to Microsoft Access through Java
  3. How to fetch data from a Microsoft Access database through JDBC and insert the table as a test field in an Applet
  4. How to use Microsoft Access Database's Attachment Data Type?
  5. Save Changes From Dataset to Microsoft Access Database
  6. Dynamic Crystal Report using Dataset, Microsoft Access Database
  7. How to Read Table Data from Microsoft Access Database in Mule ESB?
  8. "Too few parameters" trying to connect to a Microsoft Access database in R
  9. Your microsoft access database or project contains a missing or broken reference to the file dao2535.tlb version 3.5
  10. VB the microsoft access database engine could not find the object
  11. Slow execution of queries on a Microsoft Access database via ADO .Net
  12. Microsoft Access database on Samba can't be opened by multiple users at once.
  13. What are the implications of running a Microsoft access database in both 2003 and 2007?
  14. Unrecognized database format'C:\.....\Employees.accdb for Microsoft Access Database File?
  15. 'The Microsoft Access database engine cannot find a record in the table
  16. Code that can be used to iterate over every control on all reports in a Microsoft Access database?
  17. Upload a Microsoft Access Database into a Microsoft SQL Server Express Database
  18. Manipulating an Access database from Java without ODBC
  19. Connecting to Access database with PHP

How to access microsoft access database (1997) in java

Posted on Nov 25, 2013 10:48 AM,

I try to connect and use microsoft access database 1997 in java with driver : sun.jdbc.odbc.JdbcOdbcDriver You can find below the code used : Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\ft120.mdb"; Conn...

Read RepliesRead Related

How to connect to Microsoft Access through Java

Posted on Mar 15, 2014 8:59 AM,

I've been doing some research the last few days on connecting to Access through Java and so I know about using ODBC and connecting it to my database. As far as I know I've done that correctly but now I'm having some issues with my code. String connectionString = "jdbc:odbc:Driver={Microsoft...

Read RepliesRead Related

How to fetch data from a Microsoft Access database through JDBC and insert the table as a test field in an Applet

Posted on Apr 19, 2009 10:36 AM,

I have made a small letter game as a Java Applet. I have made a Microsoft Access Database through JBDC for the high scores. I have managed to insert values (scores) into the database, but I am having trouble fetching them and displaying the table in the textArea of an ajFrame...

Read RepliesRead Related

How to use Microsoft Access Database's Attachment Data Type?

Posted on Jun 25, 2011 11:48 AM,

I'm trying to use Microsoft access database's attachment data type. but i don't know how to use it. I want to insert image into access database using .Net Windows Form. In SQL Server 2008 Image data type and byte is compatibility for that. but i don't know how to insert image into...

Read RepliesRead Related

Save Changes From Dataset to Microsoft Access Database

Posted on Mar 11, 2014 4:12 AM,

I'm having a problem updating a Microsoft Access Database using a Dataset through VB.NET. Usually this method of updating a database would work for me with MySql, however after using local Access database files I'm unable to update the file with the new data. Any help is appreciated! ...

Read RepliesRead Related

Dynamic Crystal Report using Dataset, Microsoft Access Database

Posted on Jun 04, 2014 11:01 AM,

I'm trying to get a report from a custom query accessing to a Microsoft Access Database filling a Dataset and then a CrystalReportViwer but I just got an empty report with the column names. This is my connection: public String ConectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data"; ...

Read RepliesRead Related

How to Read Table Data from Microsoft Access Database in Mule ESB?

Posted on Jul 16, 2014 1:02 AM,

Currently I am working with mule ESB and trying to read data from a table in microsoft access database. I found some info that I need to configure the connection by using "bean" instead of using "database specific" option. But, I don't know how to do so. Anyone can help me and give...

Read RepliesRead Related

"Too few parameters" trying to connect to a Microsoft Access database in R

Posted on Jul 25, 2014 8:22 AM,

I'm using RODBC to connect to a microsoft access database. Some queries work fine, but on one I keep getting the errors: 07002 -3010 [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1. [RODBC] ERROR: Could not SQLExecDirect 'SELECT baseunit FROM archiverapp_common_unit...

Read RepliesRead Related

Your microsoft access database or project contains a missing or broken reference to the file dao2535.tlb version 3.5

Posted on Aug 04, 2014 4:18 AM,

We are using a database on MS Access 2000. When we want to open the database on later versions than Access 2000, we receive the following message: your Microsoft access database or project contains a missing or broken reference to the file dao2535.tlb version 3.5 Please advise....

Read RepliesRead Related

VB the microsoft access database engine could not find the object

Posted on Jan 23, 2014 6:48 AM,

I'm receiving the following run time error on VB (Excel 10) "the microsoft access database engine could not find the object". The "Database" is a defined named within a worksheet but it wont pick it up. Any ideas would be hugely appreciated!! Sub ConnectDB() If cnn.State <> adState...

Read RepliesRead Related

Slow execution of queries on a Microsoft Access database via ADO .Net

Posted on Mar 10, 2014 6:09 AM,

I am reimplementing a C++ layer into a C# layer at my company. SQL queries are executed in the layer on a Microsoft Access database via an ODBC datasource. The database is a .mdb file and the ODBC datasource uses the following driver : Microsoft Access Driver (*.mdb). The C++ layer...

Read RepliesRead Related

Microsoft Access database on Samba can't be opened by multiple users at once.

Posted on Mar 27, 2014 12:02 PM,

I think I have backed myself into a corner. I offered to help a small family business by setting up a Samba file server. Everything works great except for their Microsoft Access database. On windows the .mdb file can be opened simultaneously by multiple users across the network, but when the .mdb...

Read RepliesRead Related

What are the implications of running a Microsoft access database in both 2003 and 2007?

Posted on Sep 16, 2008 1:09 AM,

What are the implications of running a Microsoft Access Database in both 2003 and 2007? Is there some class I forgot to take? The program was originally built in office 2003, and then run in 2007. Issues seem to happen when the machine it is being run on has both 2003 and 2007 on it....

Read RepliesRead Related

Unrecognized database format'C:\.....\Employees.accdb for Microsoft Access Database File?

Posted on Apr 18, 2014 6:49 AM,

I am trying to access a file stored in a Microsoft access database.(I am working in Visual Studio 2012) I chose the Database source type, and the Dataset database model, when it asks me "which data connection should your application use to connect to the database?", I clicked New Connection, then i chose ...

Read RepliesRead Related

'The Microsoft Access database engine cannot find a record in the table

Posted on Jul 22, 2014 2:53 AM,

I am incurring a message saying 'The Microsoft Access database engine cannot find a record in the table "Process Prices' with key matching field(s) 'Process'. There is Quote table which has a field 'process' that is linked to Process Name ID in a table 'Process Name'. Within this table...

Read RepliesRead Related

Code that can be used to iterate over every control on all reports in a Microsoft Access database?

Posted on Aug 21, 2014 7:58 AM,

Can anyone suggest c# code that can be used to iterate over every control on all reports in a Microsoft Access database? The reason for doing this is that I am converting reports from Microsoft Access to Reporting Services and I want to find all reports in access that has specific text in the...

Read RepliesRead Related

Upload a Microsoft Access Database into a Microsoft SQL Server Express Database

Posted on Sep 10, 2014 9:48 AM,

I am trying to upload a Microsoft Access Database into a Microsoft SQL Server Express Database. The structure of the Access and the SQL Database are identical except for the name of the Primary Key. Error Code: System.InvalidOperationException: No data exists for the row/col...

Read RepliesRead Related

Manipulating an Access database from Java without ODBC

Posted on Feb 22, 2014 7:55 AM,

I want to manipulate a Microsoft Access database (.accdb or .mdb file) from my Java project. I don't want to use the JDBC-ODBC Bridge and the Access ODBC driver from Microsoft because: the JDBC-ODBC Bridge has been removed from Java SE 8 and is not supported (ref: ...

Read RepliesRead Related

Connecting to Access database with PHP

Posted on Nov 21, 2013 1:58 AM,

I have a simple access database I am trying to connect to using PHP. If I use this connection string: $conn = new COM('ADODB.Connection') or exit('Cannot start ADO.'); $rs = new COM("ADODB.RecordSet") or exit('Cannot start Recordset.'); $connstring = "Provider=Microsoft.Jet.OLEDB.4.0; Data...

Read RepliesRead Related
 
 
Email:

Username:

Password:


Register

Username:

Password:

Login