Blog Archives
Java Server Faces, SQL SERVER and CHAR FIELDS
I have modified the excellent JTDS driver to strip the spaces from CHAR FIELDS so that Java Server faces controls do not get confused when fields are of different lengths and also when you go to edit a field you don’t get a pile of spaces at the end of the text.
The problem.
Well I have a project where the people who originally designed the database were obviously monkeys. So they used CHAR fields throughout the database. But not all the same size, for example:-
TABLE 1 (SERVICE CODES) SERVICE CODE CHAR 2 JI
Then in an other table
TABLE 2 SERVICE CODE CHAR 50
This means that if you create a drop down box on a page with the service code list it would be padded and would not match the other table. I initially started modifying the SQL code to CAST service code as a CHAR to match the other one. Since there were 100 odd tables this meant masses of extra work to use Java Server Faces.
The other problem is that editing fields have extra spaces at the end of the data – what a nightmare.
So I pulled down the open source JTDS driver and rewrote it to trim all spaces from CHAR fields, thus making JSF work right and solving my SPACE problem.
The files are here
Source Code (converted into a Netbeans Project)
Note if you download and use this you do so at your own risk, no warranty, implied or otherwise is provided for this software.
Note 2: if you were using an OLD jdts driver you will need to remove the references from the SERVER as well as NETBEANS and use this new one – I might get round to renaming the driver to something else but if you find there are spaces where there should not be its probably because you are running the standard driver not the new one.
Note 3: If you just want the driver its in the “dist” subdirectory, you need the LIB folder as well.
Note 4: If you publish a project using this driver and modify the driver then publish it again, NB won’t change the driver on the glassfish server if it has the same name, so you’ll have to copy it over yourself.
Using SQL Server 2000 with Netbeans 6.1 (can’t see any tables)
Right
I’m just starting a HUGE project which has a SQL sever 2000 database at the back. So I configured up the SQL database and couldn’t see any tables…
The problem?
I needed to select the dbo schema not the name of the database. So your settings should be like this:-
Connection String: jdbc:sqlserver://192.168.100.11:1433;databaseName=(database name)
Schema (this is the important bit) : dbo
For some reason I mistook the Schema for the DATABASE NAME which in NB is a completely different thing.
I also tried the jtds driver and decided to use that – it’s open source and provides even faster connection.
Note that ODBC is old hat now and you should not use it as it’s really slow and probably ends up using the same sort of code you would use directly but with extra layers.