DatabaseMetaData getColumns :- type_name returns 'int identity' (SQLServer)
Hi all,
I am using the JDBC DatabaseMetaData API, getColumns() method. The back end is SQLServer 2005.
Now according to how the API is specified, I am using index 6(I think)(type_name) to retrieve the data type name from the resultset for each column.
However, for one column I am getting the datatype as "int identity".
This column has been set as identity with increment 1 in SQLServer 2005. But when I say type_name, why am I getting this "identity" word?? Should'nt I just be getting "int"??
I have found this problem to be unique to SQLServer... unless of course if someone has found this same behaviour on some other DB vendor.
Does anyone have any reason as to why, for SQLServer, this type_name index returns the "<datatype> + 'identity' "?
Actually, in my project, I just need the actualy data type only!! I do not need the identity keyword at all! (So I had to create a work around where it would ignore thhis word and just take the data type.... :-( )
Thanx.
[Check this|http://media.datadirect.com/download/docs/connectsqlxml/jdbcug/jdbcsqls.htm] and search for "data types".
(This info should also be found in the docs for the Driver.)
Every DB defines its own types, of course. Usually at least partially compliant with SQL 92/98. It is up to the driver to map those types to the JDBC types.
You can also see this.
There is, under Connection, a getTypeMap method. Unfortunately, if the app doesn't add any types to the map, this method returns an empty map. I haven't palyed with this, but it is definately possible that using it will only return user-defined types (mapped by the application). Then again, it may return the full Map as soon as one is added, then again, the Driver, may add the type conversions to the map itself, on initialisation, and so, it may return the complete map from from the beginning. I don't know. As I said, I haven't played with it.
Similar Messages
-
Hi,
I have the following problem.
I'm using ojdbc14.jar version 10.2.0.2.0
I'm trying to read table metadata from database using DatabaseMetaData.getColumns(...). And, when I read the size of a NVARCHAR2 column (using either COLUMN_SIZE or CHAR_OCTET_LENGTH) it returns the double of the maximum length (as if it were expressed in bytes!)
Javadocs says: COLUMN_SIZE int => column size. For char or date types this is the maximum number of characters, for numeric or decimal types this is precision.
Does anyone have the same problem?
Does anyone know if there is an open bug on this topic?
I will really appreciate your help
Thanks
ArielUBAHi Ashok,
Thanks for your answer.
I tried changing NLS_LENGTH_SEMANTICS parameter, and unfortunately it was unsuccessful :-(
I'm using NVARCHAR2 column type and in http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/initparams127.htm says the following:
NCHAR, NVARCHAR2, CLOB, and NCLOB columns are always character-based
I also tried to use (in a simple test case) the newest available driver 11.1.0.6.0. (but, for production I need ojdbc14.jar) and I got the same result.
PreparedStatement smt = connection.prepareStatement("ALTER SESSION SET NLS_LENGTH_SEMANTICS=CHAR");
smt.execute();
connection.commit();
DatabaseMetaData metaData = connection.getMetaData();
ResultSet columns = metaData.getColumns(null, "ENG_AAM_572_STD_1E", "PPROCINSTANCE", "V_LOAN_NUMBER");
dispVerticalResultSet(columns);The column length of V_LOAN_NUMBER is 31 characters and the result was:
TABLE_CAT=null
TABLE_SCHEM=ENG_AAM_572_STD_1E
TABLE_NAME=PPROCINSTANCE
COLUMN_NAME=V_LOAN_NUMBER
DATA_TYPE=1111
TYPE_NAME=NVARCHAR2
COLUMN_SIZE=62
BUFFER_LENGTH=0
DECIMAL_DIGITS=null
NUM_PREC_RADIX=10
NULLABLE=1
REMARKS=null
COLUMN_DEF=NULL
SQL_DATA_TYPE=0
SQL_DATETIME_SUB=0
CHAR_OCTET_LENGTH=62
ORDINAL_POSITION=32
IS_NULLABLE=YES
Are you sure that I'm dealing with the bug 4485954?
Do you know if there is a workaround?
Thanks in advance for your time
ArielUBA -
DatabaseMetaData.getColumns().next() goes on forever
Hi,
I am using the following code to get all the column names using DatabaseMetaData.getColumns().next()
The loop never stops. I am using Java 1.4 and downloaded the Oracle 9i's (9.2.0.8) ojdbc.jar from
http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc9201.html
My table "GA_TABLE" has only 22 columns. But this loop keeps on showing the same column names again and again.
The next() never stops.
I am running the Java program from Eclipse 3.2
Could you please help me?
I greatly appreciate your help.
Thank you.
listColumnNames(String tableName) {
DriverManager.registerDriver (new oracle.jdbc.OracleDriver());
connOracle = DriverManager.getConnection(strConnectURL, props);
DatabaseMetaData dbmeta = connOracle.getMetaData();
ResultSet dbColumns = dbmeta.getColumns(null, null, tableName,null);
for (int i =0; dbColumns.next(); i++){
log.info(dbColumns.getString("COLUMN_NAME"));
}I don't know about it... If there is a fix, it will be in the latest driver
available on the Oracle download page now, so that's the version of ojdbc14.jar
that you should try.
Also, please make a new table, just to test this bug. It can have the same
DDL as your original table, but name it something unique to the DBMS such as:
CREATE TABLE EVERYONELOVESJOE(....)
then run your little metadata query on that table, and tell us if the loop
never ends... In your original test, just how high does i get before you quit?
thanks,
Joe -
DatabaseMetaData.getColumns COLUMN_DEF
I want the description of table columns using DatabaseMetaData.getColumns().
When I loop thru the ResultSet I got an exception each time I try to read the column's default value.
Debug traces look like this :
DRVR OPER OracleResultSetImpl.getString(columnIndex=13)
DRVR WARN DBError.findMessage(errNum, obj): returned Stream wurde schon geschlossen
java.sql.SQLException: Stream wurde schon geschlossen
Everything else is just fineI don't know about it... If there is a fix, it will be in the latest driver
available on the Oracle download page now, so that's the version of ojdbc14.jar
that you should try.
Also, please make a new table, just to test this bug. It can have the same
DDL as your original table, but name it something unique to the DBMS such as:
CREATE TABLE EVERYONELOVESJOE(....)
then run your little metadata query on that table, and tell us if the loop
never ends... In your original test, just how high does i get before you quit?
thanks,
Joe -
Java.sql.DatabaseMetaData.getColumns field REMARKS is empty
I'm trying to get table and columns comments using java.sql.DatabaseMetaData.getColumns and REMARKS field from the rs . But it's empty alought there are comments defined in oracle.
In using oracle 10.2 (XE) , with jdevloper (10.1.3) and jdbc 1.4 (drivers that come with the installation).
Any ideas will be welcomeAmihay,
Your question has been discussed several times previously in this forum. Did you search the forum archives? Basically the answer to your question can be found in the Oracle JDBC Developer's Guide and Reference (which is part of the Oracle documentation and can be accessed via the OTN Web site). Refer to the section entitled Supported Connection Properties. You need to set the property "remarksReporting" to "true". The documentation also has sample code demonstrating how to set the property.
Good Luck,
Avi. -
Oracle JDBC thin driver(10g) returns "int/smallint" as JDBC Decimal type
Hi,
I am using Oracle type 4 thin JDBC driver for 10g. In our code we decide
column type by querying the database using database metadata (as code snippet below)
DatabaseMetaData dbmd = Connection.getMetaData() ;
ResultSet rs = dbmd. getColumns() ;
String fieldName = rs.getString("COLUMN_NAME");
short dataType = rs.getShort("DATA_TYPE");
String typeName = rs.getString("TYPE_NAME");
Now, if I have a table with datatype "integer", "smallint" etc,
DATA_TYPE returned from above is "3" , which is in JDBC is defined constant
for "java.sql.Types.Deciaml"
Question is , How do i exactly get DATA_TYPE code for
"integer" or "smallint" and not "Decimal" ?
I have tested with few other databases with above snippet code and they do return actual DATA_TYPE as "integer" or "smallint"
This is with Oracle 10g database and Oracle 10g thin (type4) jdbc driver.
Thanks,
Chiraguser565580,
As has been already stated, Oracle does not have data-types INTEGER or SMALLINT, only NUMBER.
So even though Oracle lets you write INTEGER, it really creates a NUMBER.
(As Joe mentioned.)
Other databases don't have a NUMBER data-type, they have INTEGER, SMALLINT, etc.
Originally, Oracle database only had three data-types:
CHAR
DATE
NUMBER
If you're going to be working with Oracle database, then you need to adapt yourself to its limitations.
So you'll probably need to define NUMBER data-types using scale and precision.
(As Kuassi mentioned.)
Good Luck,
Avi. -
Returning int array from C to Java as method parameter
Hello,
I've been trying to accomplish this
Java
int[] myArray = ... (filled with some data);
int retCode = myNativeCall(myArray);
if(retCode == 0)
doSomethingWith(myArray); //myArray gets overwritten with new data (with new size also) during the native call...
C
JNIEXPORT jint JNICALL Java_GenChav_rsaEncrypt(JNIEnv *env, jobject obj, jintArray myArray){
jintArray outbuf;
int[] new_array = .. // some function will fill this....
int new_array_length = ...//some function will give me the new size, not big, 512 max...
jint tmp[new_array_length]; //allocate..need something more ??
memcpy(tmp, new_array, new_array_lenght);
outbuf=(*env)->NewIntArray(env, new_array_length);
(*env)->SetIntArrayRegion(env, outbuf, 0, new_array_length, tmp);
myArray=outbuf;
I tought this way I would have a updated myArray ints on the Java program...
Any thought??user5945780 wrote:
Ok, let's try to be constructive here...
How I do implement a return type for my method like a int array ?First realized it has nothing to do with JNI. So the same question and answer applies to java only.
>
like:
int[] return = myNativeCall();
Yes.
Then I will look for return[0], if it is == to 0, fine, it means a successful calculation by the native code. Not sure what that means. The structure of what you return it up to you.
It can help when you are unsure of what to do in JNI....write a pseudo representation of what you want to do in a java method. Then translate that java method into JNI, everything in the pseudo method must be in the JNI code. -
Ibatis fails to return int value...
I've been trying to get IBATIS to execute a complex query and null is returned every time. I've tried to locate the error by using simpler queries and so far this is what I have discovered.
This query works:
select 1 as value from dual
And this one fails:
select distinct 4 as value from campaign
Needles to say both queries works fine when executed by hand in SQL-plus for oracle.
My xml setup for this query is:
<select id="getActiveCampaignId" resultClass="int" parameterClass="string">
select distinct 4 as value from campaign
</select>
Where the parameter is used in the complex query which doesn't work either.
Can anyone shed a little ligt on this problem ?Hmmm, it seems that my query that fails is fetching values from a number(38) column - changing this to number(11) made it work !!!
Is this a short comming to IBATIS or is this simpley impossible to store a number(38) in a java integer variable ?
I've looked around on google and cant finde anything on this - is this an unknow bug/feature ? Never the less it's buggy that the log doesnt inform me of this if it is indeed a integer conversion probem !!! -
DatabaseMetaData.getProcedureColumns not returning correct type
Here's the situation.
I have an object type.
CREATE TYPE ttest AS OBJECT (
elem1 VARCHAR2(1),
elem2 NUMBER(20),
I have an Table Type of the Object Type.
CREATE TYPE tabtest AS TABLE of ttest;
I'm using the Table Type as input to a package function.
function test (arrTabTest IN tabtest) return number;
When using the DatabaseMetaData, the getProcedureColumns tells me that the parameter is of type "TABLE".
How do I determine what the real Table Type is (ie. "tabtest")?
Thanks
Gary R. Kline
Chief Technology Architect
BVN Solutions, Inc.Hi Justin, thank you for responding.
for both the ODBC and oo4o example I am using the SQL statement below:
varSQL = "SELECT * FROM food"
The food table has two filed, a main of type varchar2 and a quantity of type number.
Both the main and the quantity are coming back to my ASP application as string type.
Thank You for the help.
Samir -
DatabaseMetaData.getColumns
Hello,
Can anyone explain which unit used for 'COLUMN_SIZE'? Bytes? Bits? I need to retreive database structure and I prefer to use JDBC but I think it isn't possible.
For instance in Oracle: Float(n) n -> number of bits. In PostgreSQL float4 4 -> number of bytes. :(
If I couldn't get the COLUMN_SIZE unit then DatabaseMetaData is 80% useless. I couldn't get anything except tables names and column names. :(
With regards,
Pavel KrupetsResultSetMetaData.getColumnDisplaySize(int) gives you the corresponding column size
-
BufferedReader returns int?
It is written in documentation that BufferedReader returns char but actually it returs int. Compiler tells something about precision loss. Sould I explicitly cast int to char?
char c1 = in1.read();
And one more. In this method 4-bytes int variable is returned, does stream actually reads 4 bytes, cos i may loose each second char?Readers read characters. Because a character can be any one of the 65535 values of char, an int is returned so that -1 can indicate the end of the file. Note that depending on the character encoding, this one character could be 1, 2, 3, or possibly even more bytes from the stream.
Do not immediately cast the result of read to a char, because then you cannot distinguish character \uFFFF from EOF. Assign the result to an int, and then you can cast it to a character if the int >= 0. -
Access 2010 Chart - Report returns an identical chart for every record in the underyling query
Hi there, I hope someone can help me with this. I've created a stacked column chart in a Report. The chart seems to be working fine but my report is returning a chart for every record in the source query. The chart adds up the days each vehicle in
a fleet was used in a given time frame. I'm not a code writer so wizarded my way to the following:
TRANSFORM Sum(QVehicleDaysUsed.[DaysOfUseThisMonth]) AS SumOfDaysOfUseThisMonth SELECT QVehicleDaysUsed.[YearMakeModelPlate] FROM QVehicleDaysUsed GROUP BY QVehicleDaysUsed.[YearMakeModelPlate] PIVOT QVehicleDaysUsed.VehicleUseForMonthStarting;
The chart seems to be producing exactly what I want but it's repeated once for every record in the source query. I don't know if this is the issue but I don't have a Master/Child field linking the chart to the report it's in - chart is unbound and therefore
won't allow me to link fields. I'd sure appreciate any help you can offer! Thanks!
(Incidentally VehicleUseForMonthStarting is a date field - ideally it should be shown as a DatePart MMMM but for whatever reason Access is balking at the Format expression.)
Thanks!GOT IT! Hurray. Obvious after giving it more thought... I had to make the report the chart was in Unbound. :) Leaving post up in case it helps someone else out.
-
Please confirm: INT columns in calculations return INT results?
Is it true that, when creating a formula-based column in Answers, dividing an INT typed logical column into an INT typed logical column will result in an INT typed result?
I must have missed something fundamental here, but it seems counter-intuitive that you can't divide two numbers--regardless of how they are defined--into each other and get a fractional result.
It only worked as expected when I changed the physical column datatype of one of the logical columns to DOUBLE. Likewise, I suppose I could unmap the logical columns and cast them as DOUBLEs.
Apparently, I missed something fundamental here. Clarification would be most welcome.
-JohnThe OP doesn't expect those columns to be logged though. He's performing an update on a table with a unique key, so GoldenGate should be extracting a fieldcomp (compressed update) record type with just the unique key values plus the column he's updating.
In my example above, I ran a straight forward "add trandata test.rowid_test" command and confirmed that GoldenGate had correctly created a supplemental log group containing my two unique key columns.
Also I reviewed the extract log and GoldenGate is already identifying the correct key values -
Wildcard TABLE resolved (entry TEST.*):
TABLE "TEST"."ROWID_TEST";
Using the following key columns for source table TEST.ROWID_TEST: COL1, COL2.
I did actually try the KEYCOLS clause of my TABLE extract parameter at the time, as a possible workaround. Unfortunately it made no difference.
I also reviewed the redo content with log miner and every column is logged into the redo, so GoldenGate is just acting on what it finds. That's why I think really this one is going to be a case of raising a bug report with Oracle Support which will probably end up with the core database team.
My testing was on 11.2.0.4 by the way. -
DatabaseMetaData.getTables() not returning tables
getTables(...) returns nothing in result set. I am using the JDBC-Thin Driver in Oracle 8.x. Is there anything extra that needs to be setup? Thanks!
did you specify the right parameters? this the following codes:
rset = sqldb[dbno].dbmd.getTables(null,null,"%",null)
under oracle 8.17 JDBC, it only return table,view and synonym -
GetColumns() returns columns twice!
I am having a problem with the Oracle JDBC driver that is causing problems.
Here is the snippett of code:
DatabaseMetaData dbmd = con.getMetaData(null,null,tablename,null);
ResultSet rs = dbmd.getColumns();
Stepping through the resultset that is returned shows that the getColumns() method returned the columns twice!
If the table has 4 columns then the resultset returns 8 rows with duplicates of each 'real' column in the table.
Other info:
using the thin driver for Oracle 8.1.6
Can anyone help here?
nullI wish I could help you but I know little of table synonyms. The only thing close that I know of is the long table names in DB2/400 vs. the 10 character restricted system names. Could it be a driver shortcoming? What DB driver and database are you using? MAybe there's a better approach to your overall problem besides sysnonyms?
Cliff
Maybe you are looking for
-
After I updated lion to 10.7.4, app store does not recognize my ID APPLE and it unable to connect me to app store in order to update/download apps? What have I to do? I have the same problem with mac mini e mac book air. Please help me!
-
How to use generated code from "Import Web Services" with Cairngorm Framework
I recently downloaded Flex Builder 3 beta 2 and tried out the wizard that lets you import web services. The code that is auto-generated makes if fairly straight forward to consume web services using the object types defined in the WSDL. No longer doe
-
FCP 7 "Share to blu-ray" burn issue.
This may not actually be a FCP issue, but possibly some of you here are experienced in the matter. Firstly, my video is 1080/24p ProRes. This is my first jump into Blu-ray, and I'm quickly learning the many work-arounds, but have run in to a problem.
-
Help, anyone! All the pics I transfer from camera to iPhoto are too dark. This only happens on this computer. They transfer fine on other computers. Is there any way to change the settings to correct this, not just correcting one photo at time? If so
-
Reinstall an app after a windows reset
reinstall an app after a windows reset