sql - How to connect an odbc database to my java code? -
i need connect odbc database java code. know connecting mdb database need use code doesn't work:
class.forname("sun.jdbc.odbc.jdbcodbcdriver"); // set ms access db have on machine string filename = "c:/porogram/pro.mdb"; string database = "jdbc:odbc:driver={microsoft access driver(*.mdb)};dbq="; database+= filename.trim() + ";driverid=22;readonly=true}"; // add on end // can connection drivermanager connection con = drivermanager.getconnection( database ,"",""); statement s = con.createstatement();
thank much.
currently i'm working jdbc-odbc bridge , code works me @ 100%:
this.jdbcuser = proputil.getvalue(configfile, "jdbc.user"); this.jdbcpass = proputil.getvalue(configfile, "jdbc.pass"); this.jdbcurl = proputil.getvalue(configfile, "jdbc.url"); this.jdbcdriver = proputil.getvalue(configfile, "jdbc.driver"); //be sure load required jdbc driver class.forname(jdbcdriver); dbconn = drivermanager.getconnection(jdbcurl, jdbcuser, jdbcpass);
properties file:
jdbc.user=db_user jdbc.pass=db_pass jdbc.url=jdbc\:odbc\:driver={microsoft access driver (*.mdb)};dbq=c\:/data/data1.mdb jdbc.driver=sun.jdbc.odbc.jdbcodbcdriver
please share more info problem stacktrace or whatever.
Comments
Post a Comment