我应该使用JDBC getNString()而不是getString()吗?

编程入门 行业动态 更新时间:2024-10-21 22:59:54
本文介绍了我应该使用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,あ,叶,叶和말,复制自 en.wikipedia/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 en.wikipedia/wiki/Unicode.

我们的大多数数据访问都是通过存储过程完成的。 Java能够通过 setObject()和 getString()(不是 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()吗?

本文发布于:2023-11-25 13:58:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630039.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不是   JDBC   getNString   getString

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!