I have sql queried for the particular data using jdbc in java.
Now I have payload text in the result set. Anyone please help how to read the payload text from resultset in JAVA. Below is my code giving exception
System.out.println(set.getString(columnumber));
I have payload text like below,
<tag1>Data1</tag1>
<tag2>Data2</tag2>
<tag3>Data3</tag3>
My issue is that the payload have 'lines' as mentioned above that cannot print using,
System.out.println(set.getString(columnumber));
Please help me to print the payload text from resultset in JAVA.
I found the solution for this issue. If the database column is payload text, to get it as a string in the resultset, added the below function in the SQL query
columnname.getCLOBVal()
This returns the payload text as string and I can able to print it in Java by using
System.out.println(set.getString(columnumber));
Thanks everyone for your valuable time to suggest idea on this.
Related
Arabic data is converting into ???? when java program queries xml payload from Oracle Table using Select statement
I have written a JDBC program to query xml type payload from Oracle table using Select statement. Few XML elements in the payload contains like FirstName, LastName etc. contains Arabic Characters. When i run my program, Select query returning the xml payload but the elements which having arabic characters are converting into ????.
I am not sure why it is happening like this.
is any one have solution for this problem?
Thanks in Advance.
I experienced this problem with java and mysql on eclipse the solution was
From eclipse click right on your project and choose properties and choose utf-8 like this photo
Then from the database chose base encoding and utf-8 tables.
Finally, all database queries must be utf-8 encoded
like this
String url = "jdbc:mysql://host/database?useUnicode=true&characterEncoding=utf8";
I have an applicaton that executes a query using NamedParameterJdbcTemplate. The resultSet is then parsed row by row using ResultSet.next().
Now in some cases during multi threading scenarios, this goes wrong. The result set is returning wrong values. When I execute the same query in SQLDeveloper, I am seeing the correct values. Not sure what could be the problem behind this.
while (rs.next()) {
count++;
long dbKy = rs.getLong("DBKY");
pAttrs = map.get(dbKy );
if (pAttrs== null) {
pAttrs= new HashMap<String, String>();
map.put(dbKy , pAttrs);
}
log.info( "PrintingResultSet!!::"+rs.getLong("DBKY")
+"::"+rs.getString(ATTR_NAME)
+"::"+rs.getString(ATTR_VAL)
+"::"+rs.getString(Constants.VAL));
pAttrs.put(rs.getString(ATTR_NAME),rs.getString(ATTR_VAL));
}
EDIT: This code is in the repo layer of SpringBoot application. Multithreading is, this issue happens when multiple requests are sent simultaneously. I have printed Thread id in my logs and it confirms that this happens only in multi threaded scenarios.
The value that is being returned actually is the value of some other row.
What values (wrong values) do you see when you are trying to display the resultset. If you see some unknown texts or symbols then probably it could be "encoding" issue. I suggest you to please refer on how to encode values like some special characters/symbols on your service layer since no doubt you will be able to see the data in the database by using the query but if that data contains some special characters/symbols then there is a need of encoding "UTF-8".
Thanks!
I am trying to convert some CF (version 10) code that was embedded inside a .cfm file into a function of a component as part of a Framework 1 application. The component is in script syntax, and the original code is in tag syntax. I didn't write the original code, and since I am still learning ColdFusion I am only trying to replicate the original code rather than re-write it.
The function reads in a file from the client and chops it up into pieces and stores the pieces in Java ByteArrays. It then makes as many queries as needed to store the byte arrays in a database. I have successfully converted everything up until the actual insertion query.
The problem I'm having is converting this portion of code, mainly the line with #objBuffer.Array()#:
<cfquery name="insertFile" datasource="#Datasource#">
INSERT INTO wt_file (file_data,file_name,file_type,file_part,rec_id)
VALUES (
<cfqueryparam value="#objBuffer.Array()#" cfsqltype="CF_SQL_blob">,
<cfqueryparam value="#rc.fileName#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#rc.fileType#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#i#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#rc.rec_id#" cfsqltype="cf_sql_varchar">)
</cfquery>
objBuffer.Array() is calling the Java method Array() on a java ByteBuffer object. When i try to do the same in script syntax like this:
fileQuery = new Query(
name="insertFile",
datasource = Datasource,
sql = "INSERT INTO wt_file
(file_data, file_name, file_type, file_part, rec_id)
VALUES (:data, :name, :type, :part, :recid)");
fileQuery.addParam(name="data", value = objBuffer.Array(), cfsqltype="CF_SQL_blob");
fileQuery.addParam(name="name", value = rc.fileName, cfsqltype="cf_sql_varchar");
fileQuery.addParam(name="type", value=rc.fileType, cfsqltype="cf_sql_varchar");
fileQuery.addParam(name="part", value=i, cfsqltype="cf_sql_varchar");
fileQuery.addParam(name="recid", value=rc.rec_id, cfsqltype="cf_sql_varchar");
/*execute query*/
fileQuery.execute();
In this syntax, the objBuffer.Array() call breaks the entire function. I have tried calling it before the parameter and passing it via a variable, but it doesn't matter where I call it. I get the same results.
The error message eclipse is giving me is not very helpful, but I'll post it anyway:
mismatched input 'struct' expecting RIGHTPAREN
0cfml.parsing.cfscript.CFParseException
null struct 137org.antlr.runtime.NoViableAltException
null function 52org.antlr.runtime.NoViableAltException
missing SEMICOLON at '(' 0cfml.parsing.cfscript.CFParseException
null function 52org.antlr.runtime.NoViableAltException
Because I am merely converting code, I am sure the is a better way to do this. I am sure there is a way to do this without using java classes but if there is a way to make this work too it would be great. Any help would be appreciated.
Thanks.
I have been trying to retrieve information from querying a specific Asset(Story/Defect) on V1 using the VersionOne.SDK.Java.APIClient. I have been able to retrieve information like ID.Number, Status.Name but not Requests.Custom_SFDCChangeReqID2 under a Story or a Defect.
I check the metadata for:
https://.../Story?xsl=api.xsl
https://.../meta.V1/Defect?xsl=api.xsl
https://.../meta.V1/Request?xsl=api.xsl
And the naming and information looks right.
Here is my code:
IAssetType type = metaModel.getAssetType("Story");
IAttributeDefinition requestCRIDAttribute = type.getAttributeDefinition("Requests.Custom_SFDCChangeReqID2");
IAttributeDefinition idNumberAttribute = type.getAttributeDefinition("ID.Number")
Query query = new Query(type);
query.getSelection().add(requestCRIDAttribute);
query.getSelection().add(idNumberAttribute);
Asset[] results = v1Api.retrieve(query).getAssets();
String RequestCRID= result.getAttribute(requestCRIDAttribute).getValue().toString();
String IdNumber= result.getAttribute(idNumberAttribute).getValue().toString();
At this point, I can get some values for ID.Number but I am not able to retrieving any information for the value Custom_SFDCChangeReqID2.
When I run the restful query to retrieve information using a browser from a server standpoint it works and it does retrieve the information I am looking for. I used this syntax:
https://.../rest-1.v1/Data/Story?sel=Number,ID,Story.Requests.Custom_SFDCChangeReqID2,Story.
Alex: Remember that Results is an array of Asset´s, so I guess you should be accessing the information using something like
String RequestCRID= results[0].getAttribute(requestCRIDAttribute).getValue().toString();
String IdNumber= results[0].getAttribute(idNumberAttribute).getValue().toString();
or Iterate through the array.
Also notice that you have defined:
Asset[] results and not result
Hi thanks for your answer! I completely forgot about representing the loop, I was too focus on the retriving information part, yes I was actually using a loop and yes I created a temporary variable to check what I was getting from the query in the form
Because I was getting the variables one by one so I was only using the first record. My code works after all. It was just that What I was querying didn't contain any information of my use, that's why I was not finding any. Anyway thanks for your comment and observations
Shortly ..I have a web app that queries an Oracle database and displays the result on a page. The problem is that I get a NumberFormatException when retrieving the data with query.list(), this happens only on some tabels. I`ve searched and found out that this is happening because some of my tabels contains BLOB and CLOB data so ..
Is there any way I can tell hibernate to search on my DB with createSqlQuery(sqlString) without retrieving the BLOB and CLOB data from my DB ?
Here is a part of my code :
Query query = session.createSQLQuery(sqlQuery).setFetchSize( Integer.valueOf(nrOfLines) );
query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);
final List<Map<String, String>> resultQueryList = query.list();
NumberFormatException stacktrace:
{java.lang.NumberFormatException#2747}Method threw java.lang.NumberFormatException' exception.
detailMessage = {java.lang.String#2875} "For input string: "4294967295""
cause = {java.lang.NumberFormatException#2747}"java.lang.NumberFormatException: For input string: "4294967295""
{java.lang.StackTraceElement#2751} "java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)"
{java.lang.StackTraceElement#2752} "java.lang.Integer.parseInt(Integer.java:495)"
{java.lang.StackTraceElement#2753} "java.lang.Integer.parseInt(Integer.java:527)"
{java.lang.StackTraceElement#2754} "oracle.jdbc.driver.OracleResultSetMetaData.getPrecisionOracleResultSetMetaData.java:303)"
{java.lang.StackTraceElement#2755} "org.hibernate.loader.custom.CustomLoader$Metadata.getHibernateType(CustomLoader.java:581)"
{java.lang.StackTraceElement#2756} "org.hibernate.loader.custom.CustomLoader$ScalarResultColumnProcessor.performDiscovery(CustomLoader.java:508)"
{java.lang.StackTraceElement#2757} "org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:524)"
{java.lang.StackTraceElement#2758} "org.hibernate.loader.Loader.getResultSet(Loader.java:1821)"
{java.lang.StackTraceElement#2759} "org.hibernate.loader.Loader.doQuery(Loader.java:697)" .......
I`ve searched a lot but found only how to read blob and clob data from DB... and what I want is exacly the opposite.
Finally found out a way to do it. I followed this article http://alessandromigliaccio.blogspot.ro/2010/11/javalangnumberformatexception-for-input.html and added to tomcat 7 the option -Doracledatabasemetadata.get_lob_precision=false
Variables that your are declaring, are holding larger values than the data types declared. You should use double or long for the same. that might resolve your problem.