简体   繁体   中英

Insertion in Excel failed

I tried inserting data into excel sheet using Java and ODBC, my URL is correct, the query to insert the data is executing, but the values are not inserted into excel sheet, i have made connection to commit and close. kindly help!

    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        con = DriverManager.getConnection("jdbc:odbc:excelDsn;readonly=false;");
        ps = con.prepareStatement("insert into [Sheet1$](FirstName, LastName) values (?,?)");
        ps.setString(1, "AA");
        ps.setString(2, "BB");
        ps.execute();
        con.commit();
        con.close();
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }

for DDL statements like insert , delete and update use ps.executeUpdate(); As your case is to insert so replace ps.execute(); with ps.executeUpdate();

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