简体   繁体   中英

Create table under schema using java

how to create a user in SQL, I am unable to do and still using "sys as dba" for connections and the password i created when installed. Also I create a schema named USER using DBeaver in oracle. but when I am creating a table in java with

final String newTable = "CREATE TABLE USER.Employee"+
                                "(empId NUMBER NOT NULL,"+
                                "name varchar2(10) DEFAULT NULL,"+
                                "PRIMARY KEY (empId))";

its not working. its giving error- java.sql.SQLSyntaxErrorException: ORA-00903: invalid table name

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:447)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:951)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:513)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:195)
at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:1036)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1336)
at oracle.jdbc.driver.OracleStatement.executeUpdateInternal(OracleStatement.java:1845)
at oracle.jdbc.driver.OracleStatement.executeUpdate(OracleStatement.java:1810)
at oracle.jdbc.driver.OracleStatementWrapper.executeUpdate(OracleStatementWrapper.java:294)
at com.sumit.batch.BatchEntry.main(BatchEntry.java:19)

please help..:)

Use PreparedStatement to create a table.

Sample:

PreparedStatement pstmt = conn.prepareStatement("create table survey (id int, name VARCHAR(30) );");

pstmt.executeUpdate();

Resource Link:

  1. JDBC PreparedStatement example – Create a table
  2. Create a Table Using PreparedStatement : Preparedstatement « Database « Java Tutorial

UPDATE for another issue:

Issue:

SQL Error [942] [42000]: ORA-00942: table or view does not exist java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist

Resolution:

Configuring Oracle

Ensure that you have a database instance available for Bamboo (either create a new one or use an existing one).

Within that database instance, create a user which Bamboo will connect as (eg bamboo-user). (tick) Remember this database user name, as it will be used to configure Bamboo's connection to this database. (info) When you create a user in Oracle, Oracle will create a 'schema' automatically.

create user bamboo-user identified by password;

Ensure that the user has the following permissions:

grant connect, resource, create table to bamboo-user;

For more, you can go through this 2 links:

  1. java.sql.SQLException ORA-00942 table or view does not exist
  2. Configuring Oracle

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