-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 34 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject:
PostPosted: Tue Mar 18, 2008 8:57 am 
Newbie

Joined: Mon Nov 26, 2007 10:37 am
Posts: 2
we changed to column from nclob to clob. It works now hovewer we had to clear the values


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2008 12:25 pm 
Newbie

Joined: Wed Oct 08, 2008 12:07 pm
Posts: 1
This works fine.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import oracle.jdbc.OraclePreparedStatement;
import oracle.jdbc.OracleTypes;

public class NChar {

public static void main(String[] args) {
try {


String url = "jdbc:oracle:thin:@dev-idr.xyz.com:1521:training";
Connection conn;
Statement stmt;
Class.forName("oracle.jdbc.OracleDriver");

/* Set the connection properties in a java.util.Properties and pass it as
* a parameter to the getConnection method.
*/
Properties connProps = new Properties();

/* Set the database user name */
connProps.setProperty("user","dev_user");

/* Set the password */
connProps.setProperty("password","secret");


/* Set the defaultNChar property to true */
//connProps.setProperty("oracle.jdbc.defaultNChar","true");
//connProps.setProperty("oracle.jdbc.convertNcharLiterals","true");


conn = DriverManager.getConnection(url,connProps);

String query =
"INSERT INTO product_detail(itemid,itemtype,description,langid) "+
"VALUES ( ?, ?, ?, ? ) ";
OraclePreparedStatement pstmt = (OraclePreparedStatement)
conn.prepareStatement(query) ;

/* NUMBER Column*/
pstmt.setInt(1,100);

/* NVARCHAR2 Column */
pstmt.setString(2,"Book");

/* NVARCHAR2 Column */
pstmt.setFormOfUse(3,(short)OraclePreparedStatement.FORM_NCHAR );
pstmt.setString(3,"===========>Oracle Database 10g - \\[ \\ \\] ^ _ ` { | } ~ € ‚ ƒ „ … † ‡ ˆ ‰ Š ‹ Œ Ž ‘ ’ “ ” • – — ˜ ™ š › œ ž Ÿ ¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Æ Ç Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ ");

/* Set the CHAR type to access the VARCHAR2 column */
pstmt.setFormOfUse(4,(short)OracleTypes.CHAR );

/* CHAR Column */
pstmt.setString(4,"Eng");

/* Execute the query */
pstmt.execute();

System.out.println(" Record inserted successfully === start fetching");

stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from product_detail");
while(rs.next()){
System.out.println(rs.getInt(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
System.out.println(rs.getString(4));
}
conn.close();

} catch( SQLException sqEx ) {
sqEx.printStackTrace();
} catch( Exception ex ) {
ex.printStackTrace();
}
}
}

===================================
If you want to use an existing connection


insert(........){

sLogger
.debug("Inserting ElementBean to FS_CONFIG_ELEMENT table ..");
OraclePreparedStatement lStmt = null;
String sql = "INSERT INTO FS_CONFIG_ELEMENT FSCE (CONFIG_ID,ELEMENT_ID,SORT_ORDER,LANG_CD,ELEMENT_VALUE,PART_ID,PART_FOOTNOTE_INDICATOR) VALUES (?,?,?,?,?,?,?)";
// Transaction should be started before calling this.
//Should we close this connection or is it the same connection that ODS is using ?
java.sql.Connection lConnection = ((JDBCObjectDataSource)lODS).getConnection();
lStmt = (OraclePreparedStatement)lConnection.prepareStatement(sql);
lStmt.setInt(1, aFSElementBean.getConfigId());
lStmt.setInt(2, aFSElementBean.getElementId());
lStmt.setInt(3, aFSElementBean.getSortOrder());
lStmt.setString(4, aFSElementBean.getLangCd());

//NCLOB or NCHAR or NVARCHAR Column
lStmt.setFormOfUse(5,(short)OraclePreparedStatement.FORM_NCHAR);
lStmt.setString(5, aFSElementBean.getDefaultValue());
lStmt.setInt(6, aFSElementBean.getPartId());
lStmt.setString(7, aFSElementBean.getPartFootNoteInd());

// Execute the query //
lStmt.execute();
sLogger.debug("Inserting ElementBean successful.");
}

// ELEMENT_VALUE here can be NCHAR or NVARCHAR or NCLOB


Top
 Profile  
 
 Post subject: Re: Oracle Unicode/UTF-8
PostPosted: Tue Apr 27, 2010 10:28 pm 
Newbie

Joined: Wed Apr 21, 2010 11:26 pm
Posts: 4
How do I do this with Hibernate Annotations?

furman wrote:
joe_the_quick wrote:
However, the main question is, whether there is some way to integrate this type of access into Hibernate, as this problem will come across any developer wanting to use the unicode datatypes of Oracle (9i+10g).

Suggestions are perfectly welcome,
Johannes


public class UTFStringType extends StringType{
public void set(PreparedStatement st, Object value, int index) throws SQLException {
if (st instanceof OraclePreparedStatement) {
((OraclePreparedStatement)st).setFormOfUse(index, OraclePreparedStatement.FORM_NCHAR);
}
super.set(st, value, index);
}
}

Use it instead of built-in string type.


Top
 Profile  
 
 Post subject: Re:
PostPosted: Tue Mar 15, 2011 6:05 am 
Newbie

Joined: Mon Jan 01, 2007 5:45 am
Posts: 4
furman wrote:

Code:
public class UTFStringType extends StringType{
    public void set(PreparedStatement st, Object value, int index) throws SQLException {
        if (st instanceof OraclePreparedStatement) {
            ((OraclePreparedStatement)st).setFormOfUse(index, OraclePreparedStatement.FORM_NCHAR);
        }
        super.set(st, value, index);
    }
}


Use it instead of built-in string type.


This works great with proxool and Oracle 11g.
I added an annotation to the field and everything seems to be great:
Code:
@Type(type = "mypackage.UTFStringType")


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 34 posts ]  Go to page Previous  1, 2, 3

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.