473,785 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JDBC - varchar or nvarchar fields?

D.
Hi, I'm starting a new application in java using JTDS jdbc driver
(http://jtds.sourceforge.net) and SQLServer 2005 Express.
I have to design the database from scratch and my doubt is if I have to use
varchar or nvarchar fields to store string data.

Any experience about performance issues using nvarchar instead of varchar
(considering that Java internally works in unicode too)?

Thanks in advance,
Davide.
May 10 '06 #1
4 13008
what is the nature of the data you are storing?
varchar sores variable length non-Unicode
nvarchar stores variable length Unicode
Essentially if your not storing multilingual data use varchar , as nvarchar
takes up twice as much storage space.
--
----
Jack Vamvas
_______________ _______________ _____
Receive free SQL tips - www.ciquery.com/sqlserver.htm
_______________ _______________ _____
"D." <d@d.com> wrote in message news:e3******** **@newsreader.m ailgate.org...
Hi, I'm starting a new application in java using JTDS jdbc driver
(http://jtds.sourceforge.net) and SQLServer 2005 Express.
I have to design the database from scratch and my doubt is if I have to use varchar or nvarchar fields to store string data.

Any experience about performance issues using nvarchar instead of varchar
(considering that Java internally works in unicode too)?

Thanks in advance,
Davide.

May 10 '06 #2
The Microsoft client-DBMS protocol sends string data in two possible
ways, and the DBMS will treat that data differently depending on
which way it was sent. If you have tables with indexes on varchar
columns, the DBMS *will not* use nvarchar data to search these
indexes, so you get ill-performing table scans. Similarly, if you have
indexes on nvarchar columns, the dbms will not use varchar data for
searches. This means your data and column types should match.
Java's 16-bit characters match the nvarchar form better. By default
most JDBC drivers for Microsoft will send string data as nvarchar so
they don't corrupt any potential 16-bit data. They also usually have
an optional property which will tell the driver to send strings as
varchar,
but they usually can't mix-and-match. Lastly, consider that you may
want to deal with internationaliz ed strings. For these reasons, I
recommend that you standardize on NVARCHAR columns for your
string data.
Yes, nvarchar takes 16 bits per char where varchar takes 8, but
nowadays scrimping every last bit of disk space is not typically a
driving economic concern.

Joe Weinstein at BEA Systems

May 10 '06 #3
D.
The application is multilingual and I've set the collation of SQL Server to
latin1
I'm tempted to use nvarchar (because jtds driver seems to send strings as
unicode), but I don't know:
1) How this will impact on performances of the application.
2) If I have to use a different sintax on my queries (for example using
N'xxxxxx' instead of 'xxxxxxx' for strings)
3) Any other issues on using nvarchar

Thanks,
Davide.

May 11 '06 #4
The N'xxxxx syntax would be redundant but not harmful. It
just means that the data in nvarchar, and if the driver is
sending strings as unicode (all MSSQL JDBC drivers do
this by default), it is unnecessary for prepared statement
parameter values. For constants it might be good.
The performance issue is as I described. The huge performance
problem comes by mismatching varchar with nvarchar. If you
stick to one, there is no problem. I believe the amount of
space taken up by nvarchar compared to varchar is a minimal
disk space issue only. Because your app. is multilingual, I
can't imagine a reason you'd continue to consider varchar.
Joe

Eg: PreparedStateme nt p = c.prepareStatem ent("select * from foo where
bar = \"N'myconstant\ " and qwe = ?");
p.setString(1, "myvariabledoes notneedacapital N");

Joe Weinstein at BEA Systems

May 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
9856
by: Sven Mayer | last post by:
Assume a database (e.g. Oracle) field is declared as a) NUMBER (length=10) b) NUMBER (length=26) c) VARCHAR2 (length=1) d) VARCHAR2 (length=50) e) DATE How do I retrieve the contents from these resultset fields and put it into a (numeric) java resp Date field? For other field types it is already clear e.g.):
6
6581
by: Junkmail | last post by:
I have an application with highly compressable strings (gzip encoding usually does somewhere between 20-50X reduction.) My base 350MB database is mostly made up of these slowly (or even static) strings. I would like to compress these so that my disk I/O and memory footprint is greatly reduced. Some databases have the ability to provide a compressed table, compressed column, or provide a user defined function to compress an indvidual...
0
3305
by: Turloch O'Tierney | last post by:
Hi, I was wondering if the unicode datatypes can be retrieved through the jdbc-odbc bridge using a java client, I am currently getting question marks from NCHAR and NVARCHAR fields, and numbers from my NTEXT field. The server is sql server 2000. Any assistance would be much appreciated. Regards,
2
9070
by: Vani Kancherlapalli | last post by:
Hi The maximum length of a nvarchar could be 4000 characters while that of varchar could be 8000. We are trying to use unicode which would require that the datatype for one our fields be converted from varchar to nvarchar. But looks like this would result in loss of existing data. Is there a way to do this without loss of data?
7
6218
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to make it better soon. Unfortunately, there is never a non-crucial time in which we can do an upgrade, so we are stuck for now. Point 1: There are multiple tables: students, courses, cross-reference
1
1952
by: Justin | last post by:
I have a SELECT query which pulls data from a mySQL 5 database using PHP When run in mySQL console I can see it pull the data from the varchar(5000) ok but when the same query is executed under PHP I cannot get any information from the varchar(5000) fields. Why would this be? Any suggestions as to what I need to look for to fix this.
4
2153
by: stuckish | last post by:
My collegue is saying that you should store text data in Sql Server i unicode fields (nvarchar) beause that .net (asp.net website) is all unicode and therefore you save some time not having to convert the data from ascii to unicode. So i thought that i should ask you experts what you saying about it? What is best for performance if you do not have to store any unicode
6
12911
by: mike | last post by:
so I keep optimizing my fields down to the minimum character length necessary i.e., varchar(15), then I find out a month later its gotta get bigger, then a few months later, bigger again, etc. Nowadays on sql server 2005 and on, how bad is it really to use varchar(max)? Is there really a big performance or storage hit or is it negligible? -Mike
3
6697
by: =?ISO-8859-2?Q?W=B3adys=B3aw_Bodzek?= | last post by:
Hi, I want to change 2 default behaviors of ms-sql server within a connection. 1. All varchar (etc.) fields should be returned as UTF-8. I know about field attribute collation and convert function, but I want simple query like: SELECT * FROM table; to return all varchars as UTF-8, no matter how the fields were defined and which collation.
0
9643
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10085
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2877
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.