ExecuteExample.java Source code

Java tutorial

Introduction

Here is the source code for ExecuteExample.java

Source

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

public class ExecuteExample {
    public static void main(String args[]) {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        } catch (Exception e) {
            System.out.println("JDBC-ODBC driver failed to load.");
            return;
        }

        try {
            Connection con = DriverManager.getConnection("jdbc:odbc:Inventory", "", "");
            Statement stmt = con.createStatement();
            stmt.execute("CREATE TABLE SalesHistory(ProductID NUMBER,Price CURRENCY, TrnsDate DATE)");
            stmt.close();
            con.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}