简体   繁体   中英

dsn less connection not working for java

I am trying to connect my .accdb database to my java application here . I have kept the database in same directory. I have used all possible solutions but its not of any use. Application works fine when i connect it through DSN. but i want to establish a connection dsn less. is there any solution? Thanks in advance here is my code:

String database="Service_Center.accdb";
String url="jdbc:odbc:Driver={Microsoft Access Driver(*.mdb,*.accdb)};DBQ="+database+"";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");      
Connection con=DriverManager.getConnection(url);
//Connection con = DriverManager.getConnection("jdbc:odbc:Service_Center","","");
String sql="Select Sr_No,Call_Date,Source,RMA_No,Item_name,Booking_Desc,Customer_name,Customer_address,Customer_contact,Call_Status From RMA_Master Where MaterialRequireStatus='"+materialStatus+"'";
PreparedStatement pst=con.prepareStatement(sql);
ResultSet rs=pst.executeQuery();    
table.setModel(DbUtils.resultSetToTableModel(rs));  
rs.close();
pst.close();
con.close();

Your ODBC driver name is malformed because it is missing a couple of spaces. The correct driver name is

Driver={Microsoft Access Driver (*.mdb, *.accdb)}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM