Java Programming - How to connect a ms access database to a swing application using netbeans.

Hi everyone,

Can anyone please tell me how can I connect my very simple swing loggin form that I created with netbeans 5.5 to a ms access database ?.

I've included the source code from the ide's source window and if anyone can please download my project from the url below @ esnips & correct it & mail it back to my e-mail address- <shehangrp@gmail.com> ,it would be a great help !.But if that's not possible the source code is given below.

URL: http://www.esnips.com/web/Java-Online

//

My Code From GUI's Code Window :

package nibmdcsd;

import java.awt.Dimension;

import java.awt.event.*;

import java.awt.*;

import javax.swing.*;

import java.awt.Point;

import java.awt.Toolkit;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.awt.*;

import java.util.*;

import java.sql.*;

import javax.swing.*;

import javax.swing.event.*;

public class loggin extends javax.swing.JFrame {

//Here I need to include the code to connect to the dataBase !.

JFrame frame;

public loggin() {

initComponents();

// Center in the screen

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

Dimension frameSize = getSize();

setLocation(new Point((screenSize.width - frameSize.width) / 2,

(screenSize.height - frameSize.width) / 2));

}

# IDE Generated Code #

private void extActionPerformed(java.awt.event.ActionEvent evt) {

int s = JOptionPane.showConfirmDialog(frame,"Are You Sure You want to Exit ?","Confirm Exit",JOptionPane.YES_NO_OPTION);

if(s==0){System.exit(0);} else{}

}

private void rstActionPerformed(java.awt.event.ActionEvent evt) {

usr.setText("");

pwd.setText("");

}

private void logActionPerformed(java.awt.event.ActionEvent evt) {

String user = usr.getText();

String pass = pwd.getText();

// Here I need to include code to compare the data entered with the value in the database to

// loggin the user as in a normal user loggin process !.

}

public static void main(String args[]) {

}

// Variables declaration - do not modify

private javax.swing.JButton ext;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JLabel jLabel4;

private javax.swing.JLabel jLabel5;

private javax.swing.JPanel jPanel1;

private javax.swing.JPanel jPanel2;

private javax.swing.JPanel jPanel3;

private javax.swing.JPanel jPanel4;

private javax.swing.JButton log;

private javax.swing.JPasswordField pwd;

private javax.swing.JButton rst;

private javax.swing.JComboBox stat;

private javax.swing.JTextField usr;

// End of variables declaration

}

// As you can see I'm really really new to java & swing so it would be of great help if anyone of you can help me!. Thank you in advance & may god bles you !.

[3188 byte] By [SHENa] at [2007-11-26 23:31:40]
# 1
You connect it by writing code to do that. And Netbeans has nothing to do with the process. Start with the JDBC tutorial: http://java.sun.com/docs/books/tutorial/jdbc/basics/index.html
DrClapa at 2007-7-10 14:43:39 > top of Java-index,Java Essentials,Java Programming...
# 2

One other thing to note is that well-designed code will keep layers of an application independent:

* Your database access code will have no mention of swing -- you should be able to reuse it in a console app.

* Your GUI code will have no method of database access -- you should be able

to test it without a database behind it.

This separation doesn't complication your code, no, no, no. It simplifies it.

DrLaszloJamfa at 2007-7-10 14:43:39 > top of Java-index,Java Essentials,Java Programming...
# 3

One other thing to note is that well-designed code

will keep layers of an

application independent

* Your database access code will have no mention of

swing -- you should be able to reuse it in a console

app.

* Your GUI code will have no method of database

access -- you should be able

to test it without a database behind it.

This separation doesn't complication your code, no,

no, no. It simplifies it.

you beat me to it, doc. too many people asking "how do I do this with " and listing about a dozen technologies that are entirely separate beasts. far too many

georgemca at 2007-7-10 14:43:39 > top of Java-index,Java Essentials,Java Programming...