+5 votes
577 views
by (3k points)
How to Connect to an Access database from NetBeans

1 Answer

+3 votes
by (3k points)

To link a database Access to Java NetBeans we will take the team ODBC to tell where is our database Java program. 1. To enter you must open the Control Panel - Administrative Tools - ODBC Data Sources. Select the tab DNS system and click on the Add ... button .

odbc1

You will be prompted to indicate the type of driver you are going to take for your database, select Driver do Microsoft Access (* .mdb), then click on the Finish button.

ODBC2

Now there that indicates where this database, click the Select button, a window where you have to find where this database will appear, you can be on your local disk or a network drive if your database Data will be used for the network. (additionally have to load the library MSINET.OCXwith instruction regsvr32 to work your database on the network).

odbc3

odbc4

Now that you've selected your database, need to put an alias to your base, an alias is a nickname that you give your database and can be the same name as your base, you give OK after you exit the ODBC.

odbc5

Since you indicated where your database you will fill in you Java project, now let's NetBeans, open your project, we will create a Package to believe from that Package, right-click Source Packages and select New - Java Package, you can call connection, but the name I leave to your judgment.

Connection1

Connection2

Now let's create our class that makes the connection to the database, right-click on our Package we create, choose New - Java Class, you can still name the class as a connection or can not name it as you wish.

Connection3

conexion4

Since we create our class, I present the code you'll take, I'll explain below.

conexionodbc1

First, you must import the sql library, you do it with the line:

import.java.sql. *;

After Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");

This line of c'digo you tell the system where you will make the connection, this is from the ODBC.

with = DriverManager.getConnection ("jdbc: odbc: aliasdetubase", "usuariodetubase", "password");

Replaces:

aliasdetubase: the alias that you put in the ODBC.

usuariodelabase: here are entering the security of your user database is usually admin.

password: here you will enter the password to access a database you.


statcounter statistics counter
...