java - Convert PostgreSQL Serial Primary Key to Oracle Statement -
i have java file connects database , code:
package movies; import java.sql.*; public class createtable { public static void main(string args[]) { connection c = null; statement stmt = null; string sql; try { class.forname("oracle.jdbc.oracledriver");//driver c = drivermanager.getconnection("jdbc:oracle:thin:@localhost:1521/xe", "username", "password");//put database connection info system.out.println("opened database within createtable.java"); stmt = c.createstatement(); sql = "create table movies " //+ "(id serial primary key,"//can't figure out statement , works if comment out. + " (name nvarchar2(255) primary key,"//i don't want primary key. + " year nvarchar2(255)," + " rating nvarchar2(16)," + " actors nvarchar2(1024))"; stmt.executeupdate(sql); stmt.close(); c.close(); } catch (exception e) { system.err.println(e.getclass().getname() + ": " + e.getmessage()); system.exit(0); } system.out.println("table created successfully"); } }
the commented part i'm running problems. i'm trying convert postgresql statement oracle 11g xe statement. have id sequential number identify it. (ie. 0001, 0002, 0003, etc.) how can this? provide example? i'm @ loss right now. i'm using netbeans 8.02, oracle 11g xe, , apache tomcat 8.0.15.0.
edit i'm trying have id column primary key. eliminate name column primary key , make id column new primary key.
i don't think can have 2 separate columns primary key that, if want primary key on 2 columns use,
edit : sql = "create table movies " + "(id int primary key," -- changes + " name nvarchar2(255)," + " year nvarchar2(255)," + " rating nvarchar2(16)," + " actors nvarchar2(1024))";
i have created table show syntax works in oracle now..
sql> create table movies 2 (id int primary key, 3 name nvarchar2(255), 4 year nvarchar2(255), 5 rating nvarchar2(255), 6 actors nvarchar2(1024)); table created.