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 .
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.
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).
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.
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.
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.
Since we create our class, I present the code you'll take, I'll explain below.
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.