我应该使用JDBC getNString()而不是getString()吗? [英] Should I be using JDBC getNString() instead of getString()?

查看:924
本文介绍了我应该使用JDBC getNString()而不是getString()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在构建一个由我们使用JDBC访问的Oracle数据库支持的Java应用程序(驱动程序 ojdbc6.jar orai18n.jar )。数据库模式主要使用 NVARCHAR2 数据类型存储文本列。

We are building a Java application backed by an Oracle database that we access using JDBC (drivers ojdbc6.jar and orai18n.jar). The database schema stores text columns primarily using the NVARCHAR2 data type.

JDBC文档,用于JDBC ResultSet getNString()特别适合与NCHAR,NVARCHAR等数据类型一起使用,但目前我们只使用 getString()

The JDBC documentation for the JDBC ResultSet says that getNString() is particularly intended for use with the NCHAR, NVARCHAR etc. data types, but at the moment we are only using getString().

这似乎工作正常,所以我想知道为什么我应该使用 getNString()而不是 getString()。如果输入非ASCII字符, getString()是否会开始失败,或者Oracle JDBC驱动程序对于我应该使用哪种方法无关紧要?

This seems to work fine, so I am wondering why I should use getNString() rather than getString(). Is getString() going to start failing if non-ASCII characters are entered, or is the Oracle JDBC driver indifferent as to which method I should use?

编辑:似乎它可能依赖于数据库: SQL Server似乎不介意您使用的,具体取决于连接参数。有没有人有关于Oracle的任何具体信息?

Seems that it may be database-dependent: SQL Server doesn't seem to mind which you use, depending on the connection parameters. Does anyone have any specific information on Oracle?

推荐答案

我已对我们的应用程序进行了测试,似乎 getNString()对于Java 6,JDBC 6,Oracle JDBC 6驱动程序和Oracle 11.1.0.6.0是不必要的。我使用的测试字符串是Δ,Й,ק,م,7,あ,叶,叶和말,复制自 http://en.wikipedia.org/wiki/Unicode

I have done a test on our application and it seems that getNString() is unnecessary with Java 6, JDBC 6, Oracle JDBC 6 drivers and Oracle 11.1.0.6.0. The test string I used was "Δ, Й, ק, ‎ م, ๗, あ, 叶, 葉, and 말", copied from http://en.wikipedia.org/wiki/Unicode.

我们的大多数数据访问都是通过存储过程完成的。 Java能够通过 setObject() getString()(不是<$)正确设置和检索上述测试字符串c $ c> setString()出于抽象原因),从接口收集数据并按预期将其写回接口。

Most of our data access is done via stored procedures. Java was able to set and retrieve the above test string correctly via setObject() and getString() (not setString() for abstraction reasons), collecting data from the interface and writing it back to the interface as expected.

因此 getString()适用于Oracle 11g的Unicode数据(如上面链接中的SQL Server),因此我们将继续使用此而不是 getNString ()

Hence getString() works ok for Unicode data with Oracle 11g (like SQL Server as in the above link) so we will continue to use this rather than getNString().

这篇关于我应该使用JDBC getNString()而不是getString()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆