Why does Alter Table not work in Java with executeQuery()? - oracle

I am trying to alter a table using java with this query. It works in SQL Dev but does not work with executeQuery() in java
query = "ALTER TABLE SYSTEM.db_s3 ADD (newColumn CHAR(15));"
PreparedStatement preparedStatement = conn.prepareStatement(query);
preparedStatement.executeQuery(); --> Error Occured in this line
Caused by: Error : 1735, Position : 49, Sql = ALTER TABLE SYSTEM.db_s3 ADD (newColumn CHAR(15)); , OriginalSql = ALTER TABLE SYSTEM.db_s3 ADD (newColumn CHAR(15)); , Error Msg = ORA-01735: Invalid ALTER TABLE Option.

Related

HSQLDB ON DUPLICATE KEY UPDATE syntax error

I try to execute following query:
SET DATABASE SQL SYNTAX MYS TRUE;
and then:
INSERT INTO mytable (id, age) VALUES (1, 1)
ON DUPLICATE KEY UPDATE id=2, age=33;
I get error:
INSERT INTO mytable (id, age) VALUES (1, 1)
ON DUPLICATE KEY
[2020-10-23 11:09:42] [42590][-5590] unexpected end of statement: required: UPDATE : line: 2
What do I wrong ?
The OP reports this in a comment:
PUBLIC.PUBLIC> SET DATABASE SQL SYNTAX MYS TRUE [2020-10-23 11:23:14] completed in 4 ms
PUBLIC.PUBLIC> INSERT INTO tblUserMetadata (userMetadataId, portalId) VALUES (1, 1) ON DUPLICATE KEY [2020-10-23 11:23:14] [42590][-5590] unexpected end of statement: required: UPDATE : line: 2
The lines show an SQL client is being used to run a script. The SQL client pre-parses the statement and thinks the statement is finished after the keyword KEY, and the keyword UPDATE is the start of a new statement. So it tries to send the incomplete SQL query to the database engine.
The MySQL syntax is in operation because the command was accepted and executed.
You can check the property settings by selecting from a system table:
SELECT * FROM information_schema.system_properties
The statement below returns true when the MySQL compatibility mode has been set:
SELECT property_value FROM information_schema.system_properties
WHERE property_name = 'sql.syntax_mys'

Cannot use a "." in a Hive table column name

I'm using Hive 2.1.1 and I'm attempting to create a table with . in a column name:
CREATE TABLE `test_table`(
`field.with.dots` string
);
When I do so I get:
FAILED: ParseException line 4:0 Failed to recognize predicate ')'. Failed rule: '[., :] can not be used in column name in create table statement.' in column specification
I must be doing something wrong because the hive documentation says:
In Hive release 0.13.0 and later, by default column names can be specified within backticks (`) and contain any Unicode character (HIVE-6013)
. is a unicode character. And idea what I might be doing?
To give you more context this is on an Amazon EMR 5.5.0 cluster. Thanks!
Source code: HiveParser
...
private char [] excludedCharForColumnName = {'.', ':'};
...
private CommonTree throwColumnNameException() throws RecognitionException {
throw new FailedPredicateException(input, Arrays.toString(excludedCharForColumnName) + " can not be used in column name in create table statement.", "");
}
Jira ticket :Disallow create table with dot/colon in column name
Please note the motivation:
Since we don't allow users to query column names with dot in the
middle such as emp.no, don't allow users to create tables with such
columns that cannot be queried
It seems create table was handled, but not CTAS nor ALTER TABLE...
hive> create table t as select 1 as `a.b.c`;
OK
hive> desc t;
OK
col_name data_type comment
a.b.c int
Time taken: 0.441 seconds, Fetched: 1 row(s)
hive> select * from t;
FAILED: RuntimeException java.lang.RuntimeException: cannot find field a from [0:a.b.c]
hive> create table t (i int);
OK
hive> alter table t change column i `a.b.c` int
hive> select * from t;
Error while compiling statement: FAILED: RuntimeException java.lang.RuntimeException: cannot find field a from [0:a.b.c]
P.s.
I have updated the documentation (look for colon)
https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL

datastage error - odbc function "SQLNumResultCols"

I am trying to select table from an oracle database using datastage.
In the ODBC Connector, If i do
select *
from Table_Name
I get this error -
'ODBC function "SQLNumResultCols" reportted: STATE=102:Native Error
Code = 0: Msg = [IBM(DataDirect OEM)][ODBC 20101 driver] 251'.
However if i use -
select cast(colA as varchar(50) as A,
cast(colB as varchar(50) as B
instead of
select *
from table_name
it works just fine. The data type of these columns is NVARCHAR2.
Is there a way to directly get it from
select *
from table_name
(there are about 20 columns in each of these tables)
Found a fix. Changed nvarchar parameter in odbc file

SQL Minus and lower/upper dont work together in Jdbc

i got a HSQLDB 2.2.9 and the following statement:
(SELECT lower(MyCol) FROM MyTable WHERE ID = ?)
MINUS
(SELECT lower(MyCol) FROM MyTable WHERE ID = ?)
And it works in my Squirrel. But when i execute this in my program which uses Jdbc i get the following exception:
Exception in thread "main" org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [(SELECT lower(MyCol) FROM MyTable WHERE ID = ? ) MINUS (SELECT lower(MyCol) FROM MyTable WHERE ID_CENTER = ?)]; Column not found: MyCol; nested exception is java.sql.SQLException: Column not found: MyCol
If i delete the lower() that statement works but its case sensitive which i want to eliminate here.
Can please someone tell me why i get this error and how to fix it?
This exception is not thrown by HSQLDB 2.2.9. If the column could not be found, the exception message would be in this form:
user lacks privilege or object not found: MYCOL
Please check your Spring data source settings.

vba ODBC gives Unspecified error when oracle table is having timestamp

I have vba code to fetch Oracle tables data in to a recordset via ODBC. But it shows some unspecified error if the oracle table is having timestamp field in it.
I have 100+ table i dont know which table will have timestamp.
I am running below query in loop to retrieve data.
Query = "Select End_Time from MyTable" 'this table has End_Time timestamp(6) field
CmdSQLData.CommandText = Query
CmdSQLData.CommandType = adcmdText
CmdSQLData.Timeout=0 set rs = CmdSQLData.Execute() 'This line shows unspecified error then the table is having timestamp field
'Then code for store data here...
RunTime Error '-2147467259 (80004005)'; Unspecified error
Oracle Table structure is :
create table MyTable (
Date_id Integer,
Date_Today Date,
End_Time Timestamp(6)
)
Please do not suggest some thing like,
select to_char(timestamp_field) from my_table
If i do above query, then the problem is not coming.
I need permanent code to handle Timestamps in Recordsets because i may not know whether the table is having timestamp field or not as i have 100+ tables
You may be running into something like the following: https://forums.oracle.com/forums/thread.jspa?messageID=4210331
Try upgrading your ODBC client.
The following code works fine for me :-
Dim con As New ADODB.Connection
Dim cmd As New ADODB.command
Dim rs As New ADODB.Recordset
con.Open "DSN=Oracle", "test", "test"
con.Execute "drop table tstest "
con.Execute "create table tstest ( a int, b Timestamp(6))"
con.Execute "insert into tstest values ( 1, current_timestamp ) "
q = "select * from tstest"
cmd.ActiveConnection = con
cmd.CommandText = q
cmd.CommandType = adCmdText
Set rs = cmd.Execute
Debug.Print rs.Fields(1)
con.Close
This is using ADO 2.8 with Oracle driver version 11.1.0.7
* NOTE : The Oracle driver comes from Oracle - you need to get it to work the :-
Instant Client Package - Basic
Instant Client Package - ODBC
You need both packages to get the driver to work. You then need to use an Instant Client connection in your ODBC data source for example :-
192.168.0.25:1521/orcl
IP:Port/Name

Resources