Simple Database application


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Simple Database application

  1. #1
    Join Date
    Oct 2004
    Posts
    101

    Simple Database application

    Can any one give me a sample java coding which connects the msaccess database, with addnew, modify delete functions.

    PLease....!
    sp

  2. #2
    Join Date
    Oct 2004
    Location
    UK
    Posts
    12
    To connect using file DSN:
    Code:
    try
    {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        String dbFile = "c:/db1.mdb"; // database file name
        String connectionString = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + dbFile + ";DriverID=22;READONLY=true}";
        Connection connection = DriverManager.getConnection(connectionString ,"",""); 
    }
    catch (Exception e)
    {
        // error handling code
    }
    Using proper DSN, you have to set up the database as an ODBC source under windows. Then, connecting is simple:
    Code:
    String dsnName = "mydatabase"; // DSN name in windows
    String url = "jdbc:odbc:" + dsnName;
    
    try
    { 
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection connection = DriverManager.getConnection(dbURL, "",""); 
    }
    catch (Exception e)
    {
         // error handling code
    }
    In both cases I left the username and password for the database as empty strings. If you need to supply a username and password, just fill in the second and third parameters of DriverManager.getConnection with the actual username and password, respectively.

    Implementing the various database functions is the same as with any other jdbc code. For example, to update a row in the mythical customer table:
    Code:
    int id = 1;
    String name = "Tom";
    String queryString = "UPDATE customer SET name = ? WHERE id = ?";
    PreparedStatement statement = connection.preparesStatement(queryString);
    statement.setString(1, name);
    statement.setInt(2, id);
    statement.execute();
    connection.commit();
    statement.close();
    The other functions can be implemented similarly, with use of java.sql.PreparedStatement and java.sql.Statement. I'll let you figure them out.

  3. #3
    Join Date
    Oct 2004
    Posts
    25

    Thumbs up

    try eva/3 Application Builder. the form designer is very powerful and you can connect your tables directly!
    Last edited by floaty; 10-28-2004 at 12:14 PM.

  4. #4
    Join Date
    Oct 2004
    Posts
    101

    thanx

    For the code and sugestion...

    I will try and reply to you all

    arjun
    sp

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center