Write Data to a Microsoft Excel Spreadsheet File : Excel « Database « Java Tutorial






import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Main {
  public static Connection getConnection() throws Exception {
    String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    String url = "jdbc:odbc:excelDB";
    String username = "";
    String password = "";
    Class.forName(driver); // load JDBC-ODBC driver
    return DriverManager.getConnection(url, username, password);
  }

  public static void main(String args[]) throws Exception {
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;

    conn = getConnection();
    stmt = conn.createStatement();
    String excelQuery = "insert into [Sheet1$](FirstName, LastName) values('A', 'K')";
    stmt.executeUpdate(excelQuery);

    rs.close();
    stmt.close();
    conn.close();
  }
}








20.36.Excel
20.36.1.A JDBC Program to Access/Read Microsoft Excel
20.36.2.Write Data to a Microsoft Excel Spreadsheet File
20.36.3.Read data from Excel worksheet
20.36.4.Read data from Excel
20.36.5.Use JDBC ODBC bridge to read from Excel