Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / August 2006

Tip: Looking for answers? Try searching our database.

Can run java program on UNIX update Access database on Windows ?

Thread view: 
moonhk - 15 Aug 2006 08:43 GMT
I have below run time error

java access_update
OK - Build connection
Setup con
Error: java.lang.NullPointerException null
java.lang.NullPointerException
       at
sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:436)
       at
sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:153)
       at java.sql.DriverManager.getConnection(DriverManager.java:512)
       at java.sql.DriverManager.getConnection(DriverManager.java:171)
       at access_update.main(access_update.java:36)

Source code
/*  access_update.java

2006/08/14 eric.leung

*
* Source : HOME
*
*/

import java.sql.*;
import java.lang.*;

public class access_update {
    public static void main(String args[]) {
        // eric_jsp is ODBC User DNS
        // String url = "jdbc:odbc:eric_jsp";

        // Using DSNless connection
        String url = "";
        String machine = "xx.xx.26.45";
        url = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)}" +
        ";SERVER= machine ;DBQ=c:\\example\\ERIC_JSP.mdb";

        Connection con;
        System.out.println("OK - Build connection");

    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    } catch (ClassNotFoundException e) {
        System.err.print("ClassNotFoundException " );
        System.err.println(e.getMessage());
    }

    try {
        System.out.println("Setup con");
        con = DriverManager.getConnection (url,"","");
        System.out.println("OK - Setup con");

        PreparedStatement p2 = con.prepareStatement("select count(*) from
pt_mstr where pt_part = ?");

       System.out.println("OK - Build PreparedStatement");
        p2.setString(1, "123");
        ResultSet r = p2.executeQuery();
        while (r.next()) System.out.println("How many rows have that value? "
+
        r.getInt(1) );
        r.close();
        p2.close();

        String sql = "Update pt_mstr set cnt = ? where pt_part = ?";
        PreparedStatement pstmt = con.prepareStatement(sql);

             // con.setAutoCommit(true);
         con.commit();
        pstmt.setInt(1,3000);
        pstmt.setString(2,"123");
           System.out.println(sql);

        pstmt.executeUpdate();

        // Close the connection
        con.close();

    } catch (SQLException ex) {
        // System.err.println("SQLException: " + ex.getMessage());
        ex.printStackTrace();
        }
     catch (Exception e) {
         System.err.println("Error: " + e.toString() + " " +
e.getMessage());
        e.printStackTrace();
         }   
    }
   
}
Michael Rauscher - 15 Aug 2006 14:56 GMT
Hi,

with respect to the subject: yes it's possible but not in the way you
tried it. You can't use a Windows ODBC driver under *nix (at least not
directly).

The most simple way to achieve this is to use a bridge. See here:
http://java.sun.com/products/jdbc/faq.html#5

Bye
Michael
moonhk - 16 Aug 2006 04:12 GMT
> Hi,
>
[quoted text clipped - 7 lines]
> Bye
> Michael

It works , thank a lot

C:\Example\javaux\rmi>java org.objectweb.rmijdbc.RJJdbcServer
Wed Aug 16 10:53:11 CST 2006: [RmiJdbc] Starting RmiJdbc Server !
Wed Aug 16 10:53:11 CST 2006: [RmiJdbc] No installation of RMI Security
Manager...
Wed Aug 16 10:53:11 CST 2006: [RmiJdbc] Binding RmiJdbcServer...
Wed Aug 16 10:53:12 CST 2006: [RmiJdbc] RmiJdbcServer bound in rmi
registry

ux /mfgusers/eric/javaux>r 130
java rjdemo
rmiHost=//ux
rmiHost=//xx.xxx
Try get connection..
Done

TUPLE: | 1 | Ellison | Larry | larry@oracle.com |
TUPLE: | 2 | Clark | Jim | jim@netscape.com |
*** eof ***
ux /mfgusers/eric/javaux>


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.