Connection problem in Win2k3 server 64 bit with JDBC - java

DriverManager#getConnection() returns null when I am deploying my JSP/Servlet package in a Windows 2003 Server environment (64 bit). The database is Microsoft SQL 2005 Enterprise Edition.
The code is:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:calsoft2k","xxx","xxx");
The same code is working without any problems in Windows XP (32 bit) box. I am using Apache Tomcat 6.X server in both production and development environment.
Any pointers?

Use a real JDBC driver instead of the (pardon me) lousy ODBC bridge driver.
Decent DB vendors supplies their own JDBC drivers. The one for SQL2005 can just be found at microsoft.com. This driver is however known not to be very optimal in both the performance and the level of JDBC API support. You could also consider the much faster and better jTDS driver instead.

Related

Strange performance Issue with SQL Server + Spring JAVA application

I am experience a strange performance issue when accessing data from SQL Server from a Spring based application. In my current setup, the Spring java application runs on a separate machine accessing data from a remote SQL Server DB. I am using NamedParameterTemplate in Spring, which I believe uses Prepared Statement to execute the query. For some reason, some of the query takes a long time to complete (approx. 2 mins). The JAVA app runs on a 64bit machine running 64bit version of Java v1.6, and the SQL Server is MS SQL Server 2008 R2.
The strangeness, is if I run the same java app from my laptop running Windows XP 32bit, running the same version of Java v1.6, the query takes less than a second, accessing the exact same remote DB server (infact, I am connected through VPN)
This shows the issue is not with the Spring framework but may be with the SQL JDBC Driver. I am using Microsoft JDBC Driver 4.0 for SQL Server (sqljdbc.jar)
I am completely clueless, as what could possibly be wrong and not sure where to start my debugging process.
I understand, there isn't much information in my question, so please let me know if you need any specific detail.
Thanks for any help/suggestions.
I think this may be due to the combination of your java version and jdbc driver failing to handshake the connection with the server. See Driver.getConnection hangs using SQLServer driver and Java 1.6.0_29 and http://blogs.msdn.com/b/jdbcteam/archive/2012/01/19/patch-available-for-sql-server-and-java-6-update-30.aspx
If so, switching to 1.6.0 upgrade 30 or higher and applying kb 2653857 ought to fix it.

Are any JDBC drivers installed as default with Windows?

I'm writing a Java program that retrieves data from an MS Access database. My code is as follows:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + databaseLocation + databaseName +";selectMethod=cursor; READONLY=true; TYPE=FASTLOAD";
con = DriverManager.getConnection(url);
I am using a basic JDBC:ODBC bridge. It seems a Type 4 driver would be better. However I'm writing the program to be used on a different PC and I would rather they do not have to install any drivers for it to work. I don't remember installing anything on my PC.
Can anyone tell me will this work with any copy of Windows? That is are the JDBC drivers I'm using installed with Windows or Java or Access by default?
No, there are no type IV JDBC drivers installed on Windows.
I'm not aware of a free type IV JDBC driver for Access.
The JDBC-ODBC bridge is available for 32-bit JVMs, but not for 64-bit. (A DLL is required that isn't part of the 64-bit JDK.)
duffymo is correct as far as I know when he / she says "there are no type IV JDBC drivers installed on Windows"
hxtt.com/access.html is not a JDBC type 4 driver it uses Samba and not a Native Protocol which is what is required for a JDBC type 4 driver.
What you need is a JDBC type 3 driver which uses its own Network protocol to communicate between the client which in your case would be the remote PC and a server component. Commercially available is the Easysoft JDBC-ODBC Bridge offers such a solution. You install the software on the machine containing the MS Access database or a machine that can use a UNC path to the access database and then you distribute the EJOB.jar file to the machines that require access to that database along with your Java application. You can use Easysoft from both 32-bit and 64-bit Java applcations.
Many powerful SQL syntax (for instance, select ... into outfile) at http://www.hxtt.com/access/sqlsyntax.html or SQL functions (for instance, GROUP_CONCAT) at http://www.hxtt.com/access/function.html are NOT supported by MS ACCESS engine at all. With HXTT Access' help, you can access local mdb/accdb file of UNIX/LINUX/MAC OS easily without any third-party component.
HXTT is AFAIK incorrect in their statement about there JDBC is type 4.
All drivers of HXTT drivers are type 4.
it uses SMB and not a Native Protocol
Wrong. It can run for embeded mode, client/server mode, in-memory mode, mapped driver, SMB protocol, http protocol, https protocol, and mobile OS.
If you choose to download and evaluate it, you will find the following information at http://www.hxtt.com/access.html ISN'T a lie:
HXTT Access contains the only type 4 JDBC(1.2, 2.0, 3.0, 4.0, 4.1) driver packages for Microsoft Access version from 95, 97, 2000, XP, 2002, 2003, 2007, to 2010, which supports transaction, embedded access, remote access, client/server mode, memory-only database, compressed database(.ZIP, .JAR, .GZ, .TAR, .BZ2, .TGZ, .TAR.GZ, .TAR.BZ2), SMB database(smb), url database(http, https, ftp), and java.io.InputStream database. Through the embedded Pure Java database engine, MS Access database can be deployed and acessed on any platform with JVM. With JDBC1.2, JDBC2.0, JDBC3.0, JDBC4.0, JDBC4.1, and SQL92 support, programmers needn't special coding, and DBA can use any Java database tool to access easily local data or remote data.

java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application

As I have installed MS office 2007 on Windows 7 64 bit and I also installed jdk 32 and 64 bit but when I try to connect to MS Access ans I already created system DSN the above exception throws by the code
There's no ODBC bridge driver DLL in the Java 64 bit code base, so perhaps that's the problem. You'll either have to buy a JDBC driver that can connect to Access or switch databases. Derby comes bundled with JDK 6 and higher. Perhaps that will serve your needs.
Java code is not bit specific and as "duffymo" says there is no ODBC bridge in Java. The ODBC bridge you are using is calling the MS ODBC driver manager with the same bit size as the ODBC bridge. The error is comming back because the ODBC driver the driver manager is trying to open is of a different size.
To resolve this you simply need to make sure the the ODBC Bridge is of the same bit size as the MS Access ODBC driver is on your machine.

Driver.getConnection hangs using SQLServer driver and Java 1.6.0_29

I didn't know where to write something about this and decided to do it here.
After loooong time debugging my program I could find out that calling Driver.getConnection(string, string, string) hangs the calling thread. Why(?), I really don't know, but I could find out that this happens with java 1.6.0_29 and not with java 1.6.0_26.
Full enviroment:
OS: Tested on both redhat 6.1 and Windows 2008
Driver: MS SQL Server JDBC Driver version 3.0.1301.101
Java Versions: 1.6.0_26 and 1.6.0_29
As I previously told it works with 1.6.0_26.
Is there anyone that has any idea what's possibly causing this? Maybe some developer? :p
Best regards,
Rui
I encountered exactly the same behaviour:
I use both Oracle XE and MS SQL Server Express on my Windows 7 64bit PC - I upgraded to java 1.6.0_29 from 1.6.0_27 (the x64 version) and was surprised to see that the same programs where able to connect to Oracle XE but not to MS SQL Server...
I traced down the problem to javax.sql.DataSource.getConnection() where it was hanging forever - because this is just an interface, the jdbc drivers raised my suspicion...
I'm using the MS SQL Server JDBC Driver 3.0.1301.202 and I even updated to SQL Server CTP (the "community technical preview") 4.0.1722.1 because my suspicion was that it has to do something with the jdbc driver - but no success: still hanging!
My workaround was to downgrade to 1.6.0_27 and -- bang: everything was fine again!
best regards
Erich
Reproduced:
Problem occurs with combination of
SQL driver 2.0
SQL driver 3.0
SQL driver 4.0 CTP 3
jTDS SQL Driver 1.2.5
SQL server 2008R2
Java 1.6.0_29
Change either SQL server version (tested on 2005 & 2008) or Java version (1.6.0_27, 1.7.0_1), and the problem doesn't occur anymore.
Client / Server OS: Windows 2008R2
Added to the Java Bug Database and is being worked on by Oracle.
Crossposted on Microsoft MSDN Data Access Forum (accepted answer: upgrade to java 7) and Oracle Java JDBC Forums (information that is added here, is also added to the Java Bug Database).
See the solution here
https://forums.oracle.com/forums/thread.jspa?messageID=9954398&tstart=0
http://social.msdn.microsoft.com/Forums/en/sqldataaccess/thread/97dce8fd-6487-4bca-80b0-492167db3e0d
"Apparently, this is related to SSL use and can be mitigated by replacing the jsse.jar in the jre/lib with that from an earlier version, for instance out of the 1.6.0_27 release. I've been confused by 1.6.0_29 working with MS JDBC and older SQL Server '05 setups which are not doing secure connections. All the newer servers (SQL Server '08 R2) fail as they require SSL and Java 1.6.0_29 does not work using jTDS or MS JDBC in this case."
As an FYI, it appears that there's a new step build #30 in the 1.6 family which fixes the issue:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7103725
I have the same hang problem, and only with java 1.6.0_29. I noticed that if I upgrade to 7.1 the problem goes away
I am so happy that I have found this forum. I had the same problem on upgrade (I actually upgraded from 1.6.0_22 to 1.7.1, then downgraded to 1.6.0_29, when the problem has occurred.
One more thing I have noticed : if I use 1.6.0_29 jre, it fails, but if I use 1.6.0_29 jdk, it works... I spent about a day trying to figure why eclipse (which was using the jre) was failing while myEclipse (which was using the jdk) was working....
How can a bug be introduced to such a late release ? (I am in the process of making a java production version recommendation).
Same problem here (SQLJDBC4, MsSQL 2008 R2, JDK1.6.0.29), but after updating to 1.6.0.30 problem was solved...
So it should be a critical bug in the DriverManager of 1.6.0.29
Upgrading to 1.6.0_30 also worked for me. Microsoft has released a statement announcing the fix in 2012 Q1. It looks like it's a Java vulnerability (BEAST).
I had the exact same issue where jBoss would hang on driver.getConnection(). However, I was using jBoss EAP 5.1, java 1.6.0_37x64, Sql Server 2005, and jtds1.2.5 as my jdbc driver.
The work around I had to use was a jvm setting at startup: -Djsse.enableCBCProtection=false and that resolved it.
I don't consider this a fix, but rather a work-around at this point.
I did find a bug: 7105007 : Microsoft & jTDS JDBC driver broken after update to 1.6.0_29 that was very similar, but had a different cause. What was interesting was that it showed up on both the MS drivers and jtds drivers.

How Do I Access Connection With Java?

I want to access connection on java. But i cant, because it is there odbc problem. Iam useing Windows7 x64. It's not installed odbc driver on windows 7. And is there just System DSN on Odbc Data Source Administator. I want to add but no odbc driver, only sql server.
What can i do?
If you are working on 64 bit version of Windows then you can use 64 bit and 32 bit environment. Such environment consist of Java (JDK or JRE) and database drivers. For Java applications the best way of accessing database is via JDBC driver. Then you need not to worry about 32 or 64 bit environment, you only put .jar file or files in directory that is part of CLASSPATH environment variable.
In case of MS Access you can use JDBC-ODBC bridge that is present by default in Sun (now Oracle) implementations of JRE. But before that you must configure ODBC connection with MS-Access database. This can be done via ODBC Manager or via connect string.
I think connect string is easier, because it looks like:
jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\\Nwind.mdb
all you have to do is to point at your .mdb file. This should work with 32 and 64 bit versions of JRE.
If you want to configure database access in ODBC then do it for both 32 and 64 bit environments using:
c:\windows\syswow64\odbcad32.exe (32 bit)
c:\windows\system32\odbcad32.exe (64 bit)
Then in connect string you can use DSN name you have just created like:
jdbc:odbc:DSN_NAME
You should consider JDBC-ODBC bridge, for example from OpenLink.
The usual way to access a Db with Java is with a JDBC driver. Most databases have JDBC drivers. Click here for the JDBC tutorial

Categories