Results 1 to 6 of 6
  1. #1
    needjavahelp is offline Member
    Join Date
    Jul 2010
    Posts
    1
    Rep Power
    0

    Default connect java to MS Access Database

    Hi,

    I am newbie to java programming. Now i am trying to connect the java program to Ms access database. So Far i have the following coding which i developed to connect to MS Access database. I am trying to change the name in the database table using the update query. Is this Code correct? And also Please tell me how to run the java program which has database connection?

    Please Anyone here help me out in this regard...
    PHP Code:
    import java.sql.*;
    
    class a
    {
    public static void changelastname()
    {
    String sql = "update employee set lname='yyy' where id=1";
                st.executeUpdate(sql);
    
                System.out.println("Table updated.");
    }
    public static void main(String[] args)
    {
    try 
    {
    
    System.out.println(“Begining conn”);
    
    Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
    
    String accessFileName = “company”;
    
    String connURL=”jdbc:odbc:;DRIVER=Microsoft Access Driver (*.mdb);DBQ=”+accessFileName+”.mdb;PWD=”;
    
    Connection con = DriverManager.getConnection(connURL, “”,”");
    
    System.out.println(“Conn done succesfully”);
    
    }
    changelastname();
    stmt.close();
    con.close();
    }
    catch (Exception err) {
    System.out.println(“ERROR: ” + err);
    }
    }
    }

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    "Is this code correct?" is not a good question.
    You need to tell us what's wrong...we're not going to run it, but we can bug fix if you tell us what the bug is.

    For starters does it compile?

  4. #4
    nitinverma is offline Member
    Join Date
    Mar 2010
    Location
    New Delhi,Vadodara
    Posts
    50
    Rep Power
    0

    Default

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("Jdbc:Odbc:bank");
    Statement st=con.createStatement();

    bank is the DSN Name.

  5. #5
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Okay? And this has to do with what? Especially since the OP is obviously inteding to make a DSNLess connection which is possible and inifinitly more flexible.

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,525
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Tolls View Post
    For starters does it compile?
    I guess not; the OP must've copied/pasted that code from an electronic text because most of those double quotes are incorrect. But not all of them so I suspect the code to be glued together; the new way of programming ...

    kind regards,

    Jos

Similar Threads

  1. Java SE Database Access
    By appdevman in forum New To Java
    Replies: 1
    Last Post: 06-23-2010, 05:34 PM
  2. how to connect java to MS Access database
    By Manfizy in forum New To Java
    Replies: 4
    Last Post: 12-24-2009, 04:50 PM
  3. java with access database
    By ashin in forum SWT / JFace
    Replies: 4
    Last Post: 07-12-2009, 05:04 PM
  4. Replies: 3
    Last Post: 09-18-2008, 03:07 PM
  5. Replies: 2
    Last Post: 06-12-2008, 07:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •