Accessing Ms access data in JAVA GUI Envi.

Ads

 
 

Share on Google+Share on Google+

Shashi Bhusan Pandit
Accessing Ms access data in JAVA GUI Envi.
1 Answer(s)      5 years and 2 months ago
Posted in : JDBC

Q.How to insert data into ms access data in java using swing ? Q.How to slove (access denided ("java.lang.RuntimePermission" "accessClassInPackage.sun.jdbc.odbc")" these exception ?

Ads
View Answers

August 28, 2012 at 1:05 PM


Here is an example that connect MS Access database with java swing. But first of all you need to set the connection.

Follow these steps:

1)Go to the start->Control Panel->Administrative Tools-> data sources.

2)Click Add button and select the driver Microsoft Access Driver(*.mdb).

3)After selecting the driver, click finish button.

4)Then give Data Source Name and click ok button.

5)Your DSN will get created.

6) Restart your compiler and compile your java code.

import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class  InsertData{
    public static void main(String[] args){
        JFrame f=new JFrame();
        f.setLayout(null);
        JLabel lab1=new JLabel("Name : ");
        JLabel lab2=new JLabel("Address: ");

        final JTextField text=new JTextField(20);
        final JTextArea area=new JTextArea(5,20);
        JScrollPane pane=new JScrollPane(area);
        JButton b=new JButton();

        lab1.setBounds(10,10,100,20);
        text.setBounds(120,10,150,20);

        lab2.setBounds(10,40,100,20);
        area.setBounds(120,40,150,60);

        b.setBounds(120,110,100,20);
        b.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                String st1=text.getText();
                String st2=area.getText();
             try{
             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             Connection con = DriverManager.getConnection("jdbc:odbc:roseindia");
             PreparedStatement pstmt = conn.prepareStatement("insert into data(name,address) values(?,?)");

             pstmt.setString(1, st1);
             pstmt.setString(2, st2 );
             pstmt.executeUpdate();

             JOptionPane.showMessageDialog(null,"Inserted Successfully!");
             }
             catch(Exception ex){}
            }
        });
        f.add(lab1);
        f.add(text);
        f.add(lab2);
        f.add(area);
        f.add(b);
        f.setVisible(true);
        f.setSize(350,200);
    }
}

Ads









Related Tutorials/Questions & Answers:
Accessing Ms access data in JAVA GUI Envi.
Accessing Ms access data in JAVA GUI Envi.  Q.How to insert data into ms access data in java using swing ? Q.How to slove (access denided ("java.lang.RuntimePermission" "accessClassInPackage.sun.jdbc.odbc")" these exception
accessing ms access through jsp
accessing ms access through jsp  i have 3 tables in my database employee,project,task if i put employee id the search field .i should get details from other table what all queries should i use in servlet file and i am using
Advertisements
cannot insert data into ms access database - Java Server Faces Questions
cannot insert data into ms access database   go back... connection: 1. Open Data Sources (Start->Control Panel->Administrative Tool->Data Sources(ODBC) 2. Open User DSN tab 3. Add a user DSN 4. Select
Accessing MS ACCESS databse using a HTML webpage [created using Javascript]
Accessing MS ACCESS databse using a HTML webpage [created using Javascript]  HI team, This is Srinivas, and I have a query and i explained here... I have to save some datas in an MS ACCESS database file [*.mdb], after
java &ms access - JDBC
java &ms access  Seasons Greetings, Am, creating an application for a food festival using Java swing as front end and MS access as Backend... ve managed to populate the JComboBox using MS Access. The problem is only 8 per
how to access the MS ACCESS database with java
how to access the MS ACCESS database with java   how to access the MS ACCESS database with java how can we insert,delete,update,search records of ms access with java   Java MS Access database connectivity Follow
MS Access connct using flex with java
MS Access connct using flex with java  Hi All, Can anybody help me how to connect to the MS access database and getting the data using flex in java technology with tomcat server
How To Insert A New Record to MS Access table database in GUI
How To Insert A New Record to MS Access table database in GUI  Hello, I've been working on the actionPerformed part of my java application that involves inserting a record into a 6-column table in my MS Access database table. I'm
ms access
ms access  how to delete the autonumber from ms access using java delete code
how to access the MS ACCESS database with java - Java Beginners
how to access the MS ACCESS database with java  how can we insert,delete,update,search records of ms access with java
How to Validate JRadioButton and How to Save data from JRadioButton to MS Access Database - Java Beginners
How to Validate JRadioButton and How to Save data from JRadioButton to MS Access Database  Hello Sir I want Store Corse Type that contains Two JRadioButton I want Store Information from JRadioButton to MS Access Database, and I
Ms Access
Ms Access   How to get query for Primary key from MsAccess?  ... = 'data';   SELECT column_name FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE table_name = 'data'; In the above query, data is our table name
MS-Access
MS-Access  I am trying to upload a image to ms-acess using jsp,and my...: [Microsoft][ODBC Microsoft Access Driver]COUNT field incorrect ".I think i set... the data type as OLE Object. Is there any suggestion? my code was.. <%@page
MS access
MS access  how do i access my Ms-Access file placed in the same jar file where my application code/class file r present??? Want to access it via Code. Can anyone help me ? Please give reply urgent...   give me reply
java to MS Access conectivity - Swing AWT
java to MS Access conectivity  give me source code to stored... database on the ACCESS.  Hi Friend, Follow these steps: 1. Open Data Sources (Start->Control Panel->Administrative Tool->Data Sources
MS ACCESS
MS ACCESS  i have done : Insert form data into MS database...-> data sources. 2)Click Add button and select the driver Microsoft Access...)Then give Data Source Name and click ok button. 5)Your DSN will get created. 6
MS ACCESS
MS ACCESS  i have done : Insert form data into MS database...-> data sources. 2)Click Add button and select the driver Microsoft Access...)Then give Data Source Name and click ok button. 5)Your DSN will get created. 6
MS ACCESS
MS ACCESS  i have done : Insert form data into MS database Follow...-> data sources. 2)Click Add button and select the driver Microsoft Access...)Then give Data Source Name and click ok button. 5)Your DSN will get created. 6
ms access
has to login . i already created ms access page and inserted values throught... and password" from my ms access............and detail in register(table in my ms... and password " he has to login . i already created ms access page and inserted values
ms access
has to login . i already created ms access page and inserted values throught... and password" from my ms access............and detail in register(table in my ms... and password " he has to login . i already created ms access page and inserted values
ms access
has to login . i already created ms access page and inserted values throught... and password" from my ms access............and detail in register(table in my ms... and password " he has to login . i already created ms access page and inserted values
ms access
has to login . i already created ms access page and inserted values throught... and password" from my ms access............and detail in register(table in my ms... and password " he has to login . i already created ms access page and inserted values
Jdbc MS-Access question
Jdbc MS-Access question  How to delete records from the three table in MS-Access? They are in relationship with each other regarding to data field
Jdbc MS-Access question
Jdbc MS-Access question  How to delete records from the three table in MS-Access? They are in relationship with each other regarding to data field
excel to ms access
excel to ms access  hello sir i am developing a application which requires extracting data from excel sheet and place in the ms access database using java programming for example: in excel sheet i have 2 columns and more than
How to Access MS Access in jar.
How to Access MS Access in jar.  how do i access my Ms-Access file... to access it via Code or is their any alter-native?? Do i need any Driver to do this ... i m able to access a Ms-access via JDBC but cant find the file wen
Problem in accessing data from Database
Problem in accessing data from Database  hi..... i'm making a project on servlet and jsp with ms access 2007 at the backend. One field in my database is text and all others are of currency data type. If i enter 0 or null value
How to Open Picture From M.S. Access Database using Java Servlet ?
How to Open Picture From M.S. Access Database using Java Servlet ?  Hi all my Friends I have below code which insert a picture into M.S. Access Database But i m still not able to open this picture through Java using M.S. Access
How to create and Attach MS Access Reports and Crystal Reorts in Java. - Java Beginners
How to create and Attach MS Access Reports and Crystal Reorts in Java.  How to create and Attach MS Access Reports and Crystal Reorts in Java WITH MS Access 2007 Database, plz Help Me Sir
How To Display MS Access Table into Swing JTable - Java Beginners
How To Display MS Access Table into Swing JTable  How to Display Records From MS Access Database To JTable. Plz Help Me  Hi Friend...) { Vector columnNames = new Vector(); Vector data = new Vector(); JPanel p=new
how to connect java with ms access using odbc in eclipse
how to connect java with ms access using odbc in eclipse  import java.sql.*; class AccessDatabase{ public static void main(String[] args... Access Driver (*.accdb)};DBQ=student.accdb","",""); Connection con

Ads

 
Advertisement null

Ads