jdbc type1程序错误

时间:2016-07-05 09:57:30

标签: java oracle jdbc jdbc-odbc

没有编译时错误,但存在运行时错误。我通过转到controlPanel->管理工具 - >数据源 - >添加按钮 - >在XE中选择oracle>完成 - >来分配DSN。 DSN = oradsn id = system - > ok - > ok    但它还没有运行。请帮帮我

/**
* Program1.java
* This program Creates table student
* columns: SID, SNAME, MARKS
* driver: Type-1(JDBC-ODBC Bridge)
* Database: Oracle 11g
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
class Program1{
    public static void main(String[] args)throws Exception {
        //Step-1: Load driver class
            Class.forName("sun.jdbc.odbc.jdbcOdbcDriver");
            System.out.println("Driver is loaded");
        //step-2: open connection
            Connection con=DriverManager.getConnection("jdbc:odbc:oradsn","system","tiger");
            System.out.println("connection is opened");
        //step-3: create statement object
            Statement stmt=con.createStatement();
            System.out.println("statement object created");
        //prepare command
            String cmd="create table faculty(SID number(5) primarykey, SNAME varchar(10), MARKS number(5))";
        //step-4:execute command
            int i=stmt.executeUpdate(cmd);
        //step-5: print result
            System.out.println("Table is created");
        //step-6: close connection
            stmt.close();
            con.close();
            System.out.println("connection closed");
    }//main
}//Program1

0 个答案:

没有答案