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();
}
}
}
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
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 | la...@oracle.com |
TUPLE: | 2 | Clark | Jim | j...@netscape.com |
*** eof ***
ux /mfgusers/eric/javaux>