commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kaleb Akalework (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (DBUTILS-130) QueryRunner cannot correctly insert unicode characters in Oracle Database.
Date Mon, 26 Sep 2016 20:32:20 GMT

     [ https://issues.apache.org/jira/browse/DBUTILS-130?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Kaleb Akalework updated DBUTILS-130:
------------------------------------
    Description: 
I have used queryRunner to insert unicode characters succesfully in MSSQL and IBM DB2. I was
not able to successfully insert unicode into Oracle. Instead I see the reversed questions
mark are inserted, in place of the acutal data. This is the code. The below code works fine
If I'm using SQL Server 2016 or IBM DB2 10.5. 

	
Here is a sample java code I'm using. The followoing code works perfectly if executed against
SQL Server database. 

to create the table use create table TEST (test NCLOB) 


package DatabaseTesting;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;

public class DatabaseConnection {
    
	public enum DatabaseType{
		Oracle,
		MSSQLServer,
		DB2,
	}
	
	private static Connection con;
    private static String DriverName;
    private static String JDBCUrl;
    private static String _username;
    private static String _password;
    private static DatabaseType currDatabaseType;
    
	public DatabaseConnection(String Driver, String url, String username, String password){
		
	   con = null;
	   
	   DriverName = Driver;
	   JDBCUrl = url;
	   _username = username;
	   _password = password;
	   String message = "";
	   if (Driver.contains("OracleDriver")){
		   currDatabaseType = DatabaseType.Oracle;
		   message = "Connected to Oracle Database";
	   }
	   else if (Driver.contains("SQLServerDriver")){
		   currDatabaseType = DatabaseType.MSSQLServer;
		   message = "Connected to MSSQL Database";
	   }
	   else if (Driver.contains("DB2Driver")){
		   currDatabaseType = DatabaseType.DB2;  
		   message = "Connected to DB2 Database";
	   }  
	   else{
		   return;   
	   }
	   
	   try {

		   con = DriverManager.getConnection(
				   JDBCUrl, _username,
					_password);
		   
		   System.out.println(message);
		   

		} catch (SQLException e) {

			System.out.println("Connection Failed! Check output console");
			e.printStackTrace();
			return;

		}
	}
	
	public static Object[][] getBulkWriteParams() throws SQLException{ 
		List<Object[]> listOfParams = new ArrayList<>(); 
		String s = "こんにちは"; 
		//for(ContentEntry ce:cacheOfExtractedPages){ 
		try{ 
		listOfParams.add(new Object []{s}); 
		} 
		catch(Exception e){ 
		int i= 1; 

		} 
		//} 
		return listOfParams.toArray(new Object[0][0]); 
		} 
	public static void TestQueryRunner(){
		

		
			String s = "こんにちは"; 
			String SQL = "insert into TEST VALUES( ?)"; 
			try{ 

			new QueryRunner(true).batch(con, SQL, getBulkWriteParams()); 
			}catch(Exception e){
				System.out.println(e.getMessage());
			} 
			
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
       DatabaseConnection orasun12 = new DatabaseConnection("oracle.jdbc.driver.OracleDriver",

    		                                                "jdbc:oracle:thin:@usyp5mora12v:1521:orasun12",
    		                                                "kaleba", "kaleba");
       
     /*  DatabaseConnection DB2 =  new DatabaseConnection("com.ibm.db2.jcc.DB2Driver",
    		                                            "jdbc:db2://USRYE8FTS-DB:50000/VDRKALEB",
    		                                            "SA", "mobius_db2");
    	*/	   
       
       DatabaseConnection MSSQL =  new DatabaseConnection("com.microsoft.sqlserver.jdbc.SQLServerDriver",
                                                          "jdbc:sqlserver://USYP5KALEAKAL1P:1433;DatabaseName=TEST;SelectMethod=cursor",
                                                          "sa", "mobius");
       MSSQL.TestQueryRunner();
	}

}


  was:
I have used queryRunner to insert unicode characters succesfully in MSSQL and IBM DB2. I was
not able to successfully insert unicode into Oracle. Instead I see the reversed questions
mark are inserted, in place of the acutal data. This is the code. The below code works fine
If I'm using SQL Server 2016 or IBM DB2 10.5. 

	
Here is a sample java code I'm using. The followoing code works perfectly if executed against
SQL Server database. 

to create the table use create table TEST (test NCLOB) 


private Object[][] getBulkWriteParams() throws SQLException{ 
List<Object[]> listOfParams = new ArrayList<>(); 
String s = "こんにちは"; 
//for(ContentEntry ce:cacheOfExtractedPages){ 
try{ 
listOfParams.add(new Object []{s}); 
} 
catch(Exception e){ 
int i= 1; 

} 
//} 
return listOfParams.toArray(new Object[0][0]); 
} 

public void insertQueryRunner(){ 
String s = "こんにちは"; 
String SQL = "insert into TEST VALUES( ?)"; 
try{ 

new QueryRunner().batch(connection, SQL, getBulkWriteParams()); 
}catch(Exception e){} 
}


> QueryRunner cannot correctly insert unicode characters in Oracle Database. 
> ---------------------------------------------------------------------------
>
>                 Key: DBUTILS-130
>                 URL: https://issues.apache.org/jira/browse/DBUTILS-130
>             Project: Commons DbUtils
>          Issue Type: Bug
>    Affects Versions: 1.5
>            Reporter: Kaleb Akalework
>            Priority: Critical
>
> I have used queryRunner to insert unicode characters succesfully in MSSQL and IBM DB2.
I was not able to successfully insert unicode into Oracle. Instead I see the reversed questions
mark are inserted, in place of the acutal data. This is the code. The below code works fine
If I'm using SQL Server 2016 or IBM DB2 10.5. 
> 	
> Here is a sample java code I'm using. The followoing code works perfectly if executed
against SQL Server database. 
> to create the table use create table TEST (test NCLOB) 
> package DatabaseTesting;
> import java.sql.DriverManager;
> import java.sql.Connection;
> import java.sql.SQLException;
> import java.util.ArrayList;
> import java.util.List;
> import org.apache.commons.dbutils.QueryRunner;
> public class DatabaseConnection {
>     
> 	public enum DatabaseType{
> 		Oracle,
> 		MSSQLServer,
> 		DB2,
> 	}
> 	
> 	private static Connection con;
>     private static String DriverName;
>     private static String JDBCUrl;
>     private static String _username;
>     private static String _password;
>     private static DatabaseType currDatabaseType;
>     
> 	public DatabaseConnection(String Driver, String url, String username, String password){
> 		
> 	   con = null;
> 	   
> 	   DriverName = Driver;
> 	   JDBCUrl = url;
> 	   _username = username;
> 	   _password = password;
> 	   String message = "";
> 	   if (Driver.contains("OracleDriver")){
> 		   currDatabaseType = DatabaseType.Oracle;
> 		   message = "Connected to Oracle Database";
> 	   }
> 	   else if (Driver.contains("SQLServerDriver")){
> 		   currDatabaseType = DatabaseType.MSSQLServer;
> 		   message = "Connected to MSSQL Database";
> 	   }
> 	   else if (Driver.contains("DB2Driver")){
> 		   currDatabaseType = DatabaseType.DB2;  
> 		   message = "Connected to DB2 Database";
> 	   }  
> 	   else{
> 		   return;   
> 	   }
> 	   
> 	   try {
> 		   con = DriverManager.getConnection(
> 				   JDBCUrl, _username,
> 					_password);
> 		   
> 		   System.out.println(message);
> 		   
> 		} catch (SQLException e) {
> 			System.out.println("Connection Failed! Check output console");
> 			e.printStackTrace();
> 			return;
> 		}
> 	}
> 	
> 	public static Object[][] getBulkWriteParams() throws SQLException{ 
> 		List<Object[]> listOfParams = new ArrayList<>(); 
> 		String s = "こんにちは"; 
> 		//for(ContentEntry ce:cacheOfExtractedPages){ 
> 		try{ 
> 		listOfParams.add(new Object []{s}); 
> 		} 
> 		catch(Exception e){ 
> 		int i= 1; 
> 		} 
> 		//} 
> 		return listOfParams.toArray(new Object[0][0]); 
> 		} 
> 	public static void TestQueryRunner(){
> 		
> 		
> 			String s = "こんにちは"; 
> 			String SQL = "insert into TEST VALUES( ?)"; 
> 			try{ 
> 			new QueryRunner(true).batch(con, SQL, getBulkWriteParams()); 
> 			}catch(Exception e){
> 				System.out.println(e.getMessage());
> 			} 
> 			
> 	}
> 	
> 	public static void main(String[] args) {
> 		// TODO Auto-generated method stub
>        DatabaseConnection orasun12 = new DatabaseConnection("oracle.jdbc.driver.OracleDriver",

>     		                                                "jdbc:oracle:thin:@usyp5mora12v:1521:orasun12",
>     		                                                "kaleba", "kaleba");
>        
>      /*  DatabaseConnection DB2 =  new DatabaseConnection("com.ibm.db2.jcc.DB2Driver",
>     		                                            "jdbc:db2://USRYE8FTS-DB:50000/VDRKALEB",
>     		                                            "SA", "mobius_db2");
>     	*/	   
>        
>        DatabaseConnection MSSQL =  new DatabaseConnection("com.microsoft.sqlserver.jdbc.SQLServerDriver",
>                                                           "jdbc:sqlserver://USYP5KALEAKAL1P:1433;DatabaseName=TEST;SelectMethod=cursor",
>                                                           "sa", "mobius");
>        MSSQL.TestQueryRunner();
> 	}
> }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message