简体   繁体   中英

Oracle TYPE 2 JDBC Create Table Error

Here the program is to create a table using OCI driver but it is showing the following error.

错误信息

import java.sql.*;
public class CreateTable{
public static void main(String[] args)throws Exception{
Connection con;
Statement ps;
String query;
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:oci8:orcl","scott","tiger");
query="CREATE TABLE Employee (roll number(3))";
ps=con.createStatement();
ps.executeUpdate(query);
System.out.println("Table created");
ps.close();
con.close();
}
}

Try this:

try (
Connection conn = DriverManager.getConnection(
   "jdbc:oracle:oci8:orcl","scott","tiger"); // MySQL
         Statement ps = conn.createStatement();
       {
       String query="CREATE TABLE Employee (roll number(3))";
        ps=con.createStatement();
         ps.executeUpdate(query);
          System.out.println("Table created");
         System.out.println("Table created");
         }
      } catch(SQLException ex) {
         ex.printStackTrace();
      }
ps.close();
con.close();
}
}

It's better to use Type 4 Connectivity because their Java drivers are for "direct-to-database".

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