Home Answers Viewqa Applet applet connected to table in MS Access database

 
 


abhishek upamanyu
applet connected to table in MS Access database
0 Answer(s)      2 years ago
Posted in : Applet

i have connected my java code with the MS access database and this is my code, can anyone tell me how to show the table in an applet...pls

	
	import java.sql.*;

	public class TestDBDriver {
    static Connection con;
    static Statement stmt;
    static ResultSet rs;

    public static void main(String[] args) {

    //step 1: load driver
    loadDriver();

    //step 3: establish connection
    makeConnection();

    //create a table
    createTable();

    //insert data
    insertData();

    //use precompiled statement to update data
    usePreparedStatement();

    //retrieve data
    retrieveData();

    //close all resources
    closeAll();
}

// load a driver
static void loadDriver() {
    try {
        //step 2: Define connection URL
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    } catch(java.lang.ClassNotFoundException e) {
        System.err.print("ClassNotFoundException: ");
        System.err.println(e.getMessage());
    }
}

// make a connection  step 3: establish connection
static void makeConnection() {
   //for how to set up data source name see below.
   String dsn = "judydriver";


String url =
    "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=faltu.mdb";

 // String url = "jdbc:odbc:" + dsn;
    try {
       con = DriverManager.getConnection(url);
    }catch(SQLException ex) {
       System.err.println("database connection: " + ex.getMessage());
    }
}

//create a table
static void createTable() {
    String createString = "create table COFFEES " +
                      "(COF_NAME VARCHAR(32), " +
                      "SUP_ID INTEGER, " +
                      "PRICE FLOAT, " +
                      "SALES INTEGER, " +
                      "TOTAL INTEGER)";



    try {
        //step 4: create a statement
        stmt = con.createStatement();
        //step 5: execute a query or update.
        stmt.execute("drop table COFFEES");//if exists, drop it, get new one
        stmt.executeUpdate(createString);

    }catch(SQLException ex) {
        System.err.println("CreateTable: " + ex.getMessage());
    }
 }

 //insert data to table COFFEES
 static void insertData() {
    try {
        stmt.executeUpdate("INSERT INTO COFFEES " +  "VALUES ('Colombian', 101, 7.99, 0, 0)");
        stmt.executeUpdate("INSERT INTO COFFEES " +  "VALUES ('French_Roast', 49, 8.99, 0, 0)");
        stmt.executeUpdate("INSERT INTO COFFEES " +  "VALUES ('Espresso', 35, 5.99, 0, 0)");
        stmt.executeUpdate("INSERT INTO COFFEES " +  "VALUES ('Colombian_Decaf', 101, 4.99, 0, 0)");
        stmt.executeUpdate("INSERT INTO COFFEES " +  "VALUES ('French_Roast_Decaf', 49,6.99, 0, 0)");

    }catch(SQLException ex) {
        System.err.println("InsertData: " + ex.getMessage());
    }
 }

//use PreparedStatement to precompile sql statement
static void usePreparedStatement() {
    try {
        PreparedStatement updateSales;
        String updateString = "update COFFEES " +
                  "set SALES = ? where COF_NAME like ?";
        updateSales = con.prepareStatement(updateString);
        int [] salesForWeek = {175, 150, 60, 155, 90};
        String [] coffees = {"Colombian", "French_Roast", "Espresso",
                 "Colombian_Decaf", "French_Roast_Decaf"};
        int len = coffees.length;
        for(int i = 0; i < len; i++) {
            updateSales.setInt(1, salesForWeek[i]);
            updateSales.setString(2, coffees[i]);
            updateSales.executeUpdate();
        }
    }catch(SQLException ex) {
        System.err.println("UsePreparedStatement: " + ex.getMessage());
   }
}

//retrieve data from table COFFEES
static void retrieveData() {
   try {
       String gdta="SELECT COF_NAME, PRICE FROM COFFEES WHERE PRICE < 9.00";
       //step 6: process the results.
       rs = stmt.executeQuery(gdta);
       while (rs.next()) {
            String s = rs.getString("COF_NAME");
            float n = rs.getFloat("PRICE");
            System.out.println(s + "   " + n);
       }
   }catch(SQLException ex) {
       System.err.println("RetrieveData: " + ex.getMessage());
   }
 }

//close statement and connection
//step 7: close connection, etc. 
 static void closeAll() {
     try {
        stmt.close();
        con.close();
     } catch(SQLException ex) {
        System.err.println("closeAll: " + ex.getMessage());
     }
}

}

Thanks;

View Answers









Related Pages:
applet connected to table in MS Access database
applet connected to table in MS Access database   i have connected my java code with the MS access database and this is my code, can anyone tell me how to show the table in an applet...pls import java.sql.
MS ACCESS
MS ACCESS  i have done : Insert form data into MS database..., *.accdb)};DBQ=C:\\myca\\demo\\authors.accdb"); // Creating a database table... data displayed in table in my database (authors.accdb) when i run my
MS ACCESS
MS ACCESS  i have done : Insert form data into MS database Follow...)};DBQ=C:\\myca\\demo\\authors.accdb"); // Creating a database table... data displayed in table in my database (authors.accdb) when i run my
MS ACCESS
MS ACCESS  i have done : Insert form data into MS database..., *.accdb)};DBQ=C:\\myca\\demo\\authors.accdb"); // Creating a database table... data displayed in table in my database (authors.accdb) when i run my
MS Access - WebSevices
" which have access database and for images we have created a field in the table...MS Access  hello sir, i am trying to write a code which should take images from a particular folder and data from MSAccess..please help me..thank
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
Applet database access - Applet
Applet database access  HI... I'm having an applet where we should display the database values in the applet... It works fine in the local system... but when its in the server, we r getting null values in the local system.. I
Ms Access
Ms Access   How to get query for Primary key from MsAccess?   SELECT column_name FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE table_name..._USAGE WHERE table_name = 'data'; In the above query, data is our table name
how to connect to MS access database in JSP?
how to connect to MS access database in JSP?  how to connect to MS access database in JSP? Any seetings/drivers need to be set or installed before it? Please tell what needs to be done after creating a table with an example
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 wrong datatype for table column in which my image going to be saved.I set
ms access
and password" from my ms access............and detail in register(table in my ms... "username and password" from my ms access............and detail in register(table in my... has to login . i already created ms access page and inserted values throught
ms access
and password" from my ms access............and detail in register(table in my ms... "username and password" from my ms access............and detail in register(table in my... has to login . i already created ms access page and inserted values throught
ms access
and password" from my ms access............and detail in register(table in my ms... "username and password" from my ms access............and detail in register(table in my... has to login . i already created ms access page and inserted values throught
ms access
and password" from my ms access............and detail in register(table in my ms... "username and password" from my ms access............and detail in register(table in my... has to login . i already created ms access page and inserted values throught
link hibernate to MS ACCESS database
link hibernate to MS ACCESS database  how to link hibernate to ms access database instead of sql database
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
How to use JTable with MS-Access
.   Here is an example that retrieves the data from MS Access database...How to use JTable with MS-Access   I have Three Column in Database (MS-Access). 1. Name 2. City 3. Contact I want to Display
How to use JTable with MS-Access
.   Here is an example that retrieves the data from MS Access database...How to use JTable with MS-Access   I have Three Column in Database (MS-Access). 1. Name 2. City 3. Contact I want to Display
database is connected but not insert the data
database is connected but not insert the data  hi, i am getting connected to database.Retrive the data also but cannot insert the data into database...("sun.jdbc.odbc.JdbcOdbcDriver"); String url = "jdbc:odbc:Driver={Microsoft Access Driver
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... = DriverManager.getConnection("jdbc:odbc:access"); String sql = "Select * from
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
Updating Ms Access Database using jsp - JSP-Servlet
Updating Ms Access Database using jsp  Hi I am new to jsp and I am trying to update a record in an access database. I only want to update part... a table product(prod_id,prod_name,quantity,price) and try the following code
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` - IDE Questions
MS Access`  hello sir, how to configure MS Access database in Net Beans5.5... and i have a doubt, where should we run the below code...either in IDE or in any editor like EDITPLUS. waitin for your reply.... thank you
J2ME connectivity to ms access
J2ME connectivity to ms access  How to establish client server connectivity to access ms access database on the server side? I have made the odbc connection. Plz help me in the coding part.. Dont know how to start
how to access database in applet
how to access database in applet  HI... I'm having an applet where we should display the database values in the applet... It works fine in the local system(same network)... but when its in the server, we r getting null values
MS Access` - JDBC
to insert image into MS Access Database. Now the task is how to retrieve the image from database. And i am developing a JFrame to retrieve tha fields from database...MS Access`  Hello Sir, Thank you very much for your valuable
MS Access - JSP-Servlet
stepts 1.to configure the ms access database to your system control panel...MS Access  hello sir, i want to use MS.Access as my database..so my problem is how to connect MS Acces database with servlets ... thank you
MS Access - JDBC
information about MS access database...but still i am having doubt in that topic. My problem is : Is there any jar to connect MS Access and java ... because... to be remember 1.to configure the ms access database to your system control
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
Migrating from mysql to MS Access
Migrating from mysql to MS Access  Hi I am hoping for some help I need to write a conversion program (SQL statements) to import existing data in a MYSQL database to a MS Access database. any suggestions would be appreciated
How To Connect MS ACCESS 2003 Database in C Program with Graphics.
How To Connect MS ACCESS 2003 Database in C Program with Graphics.  How To Connect MS ACCESS 2003 Database in C Program with Graphics
ms access
ms access  how to delete the autonumber from ms access using java delete code
jdbc warning regarding to ms access
jdbc warning regarding to ms access  shows warning msg while compiling using ms access : warning: sun.jdbc.odbc.JdbcOdbcDriver is Sun proprietary API... visit JDBC-ODBC Bridge and download the driver for your database. b) Use
how to insert values from jsp into ms access
how to insert values from jsp into ms access   how to insert values using jsp into ms access database
to get picture from ms access database by jsp-servlet....
to get picture from ms access database by jsp-servlet....  I have inserted a picture in ms access data base,,,how we can retrieve that picture by using jsp
MS-ACCESS Query Problem - SQL
MS-ACCESS Query Problem  hi sir i have table which is initially... Sex Hostel so another table is Student Attributes: Roll Name Add Age Course Class Sex Hostel here in this table contains all the records
problem in jsp using ms-access
problem in jsp using ms-access  after starting server(tomcat) wen v... and select the driver Microsoft Access Driver(*.mdb). 3)After selecting... is your required code: <%@page import="java.sql.*"%> <table border=1>
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
from database ms-access  import javax.swing.*; import java.awt...."); JOptionPane.showMessageDialog(null,"connected to database...,"connected to database"); stat=con.createStatement(); String ss="select name from data
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
from database ms-access  import javax.swing.*; import java.awt...."); JOptionPane.showMessageDialog(null,"connected to database...,"connected to database"); stat=con.createStatement(); String ss="select name from data
show null point Exception """ while trying 2 load a JComboBox"" data is fetch from database ms-access
from database ms-access  import javax.swing.*; import java.awt...."); JOptionPane.showMessageDialog(null,"connected to database...,"connected to database"); stat=con.createStatement(); String ss="select name from data
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
HTML(Registration form) to Jsp to stored into MS ACCESS database
HTML(Registration form) to Jsp to stored into MS ACCESS database  i am sending one html file that contain 18 fields these are stored in ms-access database by using jsp code.i want to urgent jsp code. please urgent sir. thank
how to retreive values from MS Access Database based on the values entered in textbox values in jsp file
following problem. My Project requirement is as follows: I have a table in batchlogs.mdb in MS Access Database. the table structure is Sno JobName ProgramName Problem...how to retreive values from MS Access Database based on the values entered
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
How to search the table name in MS SQL Database 2005 from application
How to search the table name in MS SQL Database 2005 from application  How to search the table name in MS SQL Database 2005 from application from our helpdesk application? application might be in html
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
cannot insert data into ms access database - Java Server Faces Questions
cannot insert data into ms access database   go back   Hi Friend, You can use the following steps for creating DSN... Microsoft Access Driver(*.mdb) 5. Select database name and Create the DSN name
How to store JComboBox selected Item into Ms Access Database - Java Beginners
How to store JComboBox selected Item into Ms Access Database  How to store JComboBox selected Item into Ms Access Database.  Hi Friend...:access","",""); Statement stmt=con.createStatement(); ResultSet rs