0
votes
import java.sql.DriverManager;

import java.sql.Connection;

import java.sql.Statement;

public class Create

{

    public static void main( String [] args)throws Exception
    {
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522/orcl1","scott","sada");
        System.out.println("connection is createad");
        Statement stmt=con.createStatement();
        System.out.println("statemnt of object is createad");
        stmt.executeUpdate("create table iteam(iteamno number(3)primarykey,iteamname number(15),price number(4))");
        System.out.println("table is created ");
        con.close();
        stmt.close();
        System.out.println("conncetion closed");
    }
}

Every thing executed successfully but after Statement object it will show this error when my program executes:

java.sql.SQLSyntaxErrorException: ORA-00907: missing right parenthesis Error

1
It's primary key not primarykey - a_horse_with_no_name
I think you are missing some spaces before and after the word primary: create table iteam(iteamno number(3) primary key - Glenn

1 Answers

1
votes

A spacing error. Fixed below; you'd do well to try your statements in a fiddle before posting a question here, @sada:

import java.sql.DriverManager;

import java.sql.Connection;

import java.sql.Statement;

public class Create

{

    public static void main( String [] args)throws Exception
    {
        Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1522/orcl1","scott","sada");
        System.out.println("connection is createad");
        Statement stmt=con.createStatement();
        System.out.println("statemnt of object is createad");
        stmt.executeUpdate("create table iteam(iteamno number(3) primary key,iteamname number(15),price number(4))");
        System.out.println("table is created ");
        con.close();
        stmt.close();
        System.out.println("conncetion closed");
    }
}