Friday, February 24, 2012
jdbc-sql 2000 error
I'm having trouble connecting to Sql Server 2000 via Java 2 (5.0).
I'm on Windows Server 2003 and trying to connect locally from the
server. I've downloaded the jar files (mssqlserver.jar,msutil.jar,
msbase.jar) containing the jdbc driver from microsoft and placed them in
the same directory as my java file, below is a snippet of my code to
test the connection:
public void openTest() throws Exception
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver" );
Connection m_Conn = DriverManager.getConnection
("jdbc:microsoft:sqlserver://local:1433", "", "");
}
I compile using the following command there are no errors:
javac -classpath ".;./mssqlserver.jar;./msbase.jar;./msutil.jar"
Test.java
At runtime i get the following error,
Exception in thread "main" java.lang.ClassNotFoundException:
com.microsoft.jdbc.
sqlserver.SQLServerDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at Hello.openTest(HelloPrint.java:30)
at HelloPrint.main(HelloPrint.java:11)
Can anyone help? Many thanks in advance.
InderHi
It's been a while since I used the JDBC driver!
microsoft.public.sqlserver.jdbcdriver may be a better newsgroup to post to.
You may want to make sure the .jar files are on the classpath and you may
want to re-run the setup just in case there is some corruption.
John
"inder" wrote:
> Hi,
> I'm having trouble connecting to Sql Server 2000 via Java 2 (5.0).
> I'm on Windows Server 2003 and trying to connect locally from the
> server. I've downloaded the jar files (mssqlserver.jar,msutil.jar,
> msbase.jar) containing the jdbc driver from microsoft and placed them in
> the same directory as my java file, below is a snippet of my code to
> test the connection:
> public void openTest() throws Exception
> {
> Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver" );
> Connection m_Conn = DriverManager.getConnection
> ("jdbc:microsoft:sqlserver://local:1433", "", "");
> }
>
> I compile using the following command there are no errors:
> javac -classpath ".;./mssqlserver.jar;./msbase.jar;./msutil.jar"
> Test.java
> At runtime i get the following error,
>
> Exception in thread "main" java.lang.ClassNotFoundException:
> com.microsoft.jdbc.
> sqlserver.SQLServerDriver
> at java.net.URLClassLoader$1.run(Unknown Source)
> at java.security.AccessController.doPrivileged(Native Method)
> at java.net.URLClassLoader.findClass(Unknown Source)
> at java.lang.ClassLoader.loadClass(Unknown Source)
> at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
> at java.lang.ClassLoader.loadClass(Unknown Source)
> at java.lang.ClassLoader.loadClassInternal(Unknown Source)
> at java.lang.Class.forName0(Native Method)
> at java.lang.Class.forName(Unknown Source)
> at Hello.openTest(HelloPrint.java:30)
> at HelloPrint.main(HelloPrint.java:11)
>
> Can anyone help? Many thanks in advance.
> Inder
>|||Hi John,
I've got that error fixed; you were right, it was a classpath
problem. Now i have another error,
[Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
when i run the following,
Connection m_Conn =
DriverManager.getConnection("jdbc:microsoft:sqlserver://servername:1433;
DatabaseName=Northwind","","");
The problem is that my 'servername' is the same as my windows server
2003 domain and when i setup my sql server 2000 i set it to use the
windows authentication, so now i'm not sure what to put for the username
and password in the above string.
Many thanks again,
Inderjit
*** Sent via Developersdex http://www.examnotes.net ***|||Hi
This may help a bit.
http://support.microsoft.com/defaul...kb;en-us;313100
AFIK the JDBC driver does not support Windows Authentication as it is
not a type 4 driver. You may want to look at
http://www.jnetdirect.com/products.php?op=jsqlconnect
John
JDBC with SQL Express
The java code :
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost:1433;" +
"instance=SQLEXPRESS;databaseName=UPM;integratedSecurity=true;";
Connection con = DriverManager.getConnection(connectionUrl);
returns "connection refused" no matter what I do.
I've used the surface config tool to enable TCP, I've added sqlsrvr.exe to the firewall exceptions, I've tried a dozen or so variations on the connection string.
I can connect to the database using the Management Studio.
Any ideas what I'm missing ?
Thanks.
As you are using a trusted connection can your verify that you are using the correct user in both systems.
|||I'm running into the same problem.
No problem connecting through VWD or SQL Management Studio...
The code:
String url =
"jdbc:sqlserver://localhost;" +
//"databaseName=TV;" +
"portNumber=1433;" +
"instanceName=./SQLEXPRESS;" +
"loginTimeout=0;" +
//"userName=Pierre;" +
//"serverName=PG" +
"integratedSecurity=true;";
con = DriverManager.getConnection( url );
Same bad result with all commented parameters.
The message:
The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect.
|||
This may be because by default MS SQL Server Express is configured to use dynamic TCP/IP ports, like named instances.
Go into the SQL SERVER CONFIGURATION MANAGER
open SQL SERVER 2005 Network Configuration
open Protocols for SQLEXPRESS
open TCP/IP properties
on the IP ADDRESSES tab, check at the bottom if "TCP Dynamic Ports" has a value.
if so, clear the value and leave that field blank. Then change "TCP Port" to 1433 or whatever port you decide.
JDBC und SQL Server
Im very new in this topic.
And now I want to read some data from a SQL Server with Java.
But I dont know how.
I have now downloaded the new Driver form Microsoft and now I want to read
data from the SQL Server with Java.
Can someone give me a little example.
Sincerly Patrick Hennig
Hi Patrick,
Here's some sample code:
Connection connection = null;
try {
String driverName = "jdbc:microsoft:sqlserver://";
String serverName = "127.0.0.1";
String portNumber = "1433";
String myDatabaseUrl = serverName + ":" + portNumber;
String myDatabaseName = "DatabaseName=Northwind";
String url = "jdbc:microsoft:sqlserver://" + myDatabaseUrl + ";" +
myDatabaseName;
String username = "username";
String password = "password";
// Load the JDBC driver
Class.forName(driverName);
// Create a connection to the database
connection = DriverManager.getConnection(url, username, password);
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT CustomerId, CompanyName FROM
Customers");
while (rs.next()) {
System.out.println(rs.getString("CustomerId"));
System.out.println(rs.getString("CompanyName"));
}
rs.close();
} catch (ClassNotFoundException e) {
// Could not find the database driver
e.printStackTrace();
} catch (SQLException e) {
// Could not connect to the database
e.printStackTrace();
}
finally {
try {
connection.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
A great place to find all kinds of Java sample code is here:
http://javaalmanac.com/cgi-bin/search/find.pl?words=sql
- Tim
"Patrick Hennig" <patrick_hennig@.licht-concept.de> wrote in message
news:%23mXDLUsgEHA.3944@.tk2msftngp13.phx.gbl...
> Hi,
> Im very new in this topic.
> And now I want to read some data from a SQL Server with Java.
> But I dont know how.
> I have now downloaded the new Driver form Microsoft and now I want to read
> data from the SQL Server with Java.
> Can someone give me a little example.
> Sincerly Patrick Hennig
>
JDBC SP3 and SSL
If I enable SSL on my SQL Server (using the Force Protocol Encryption in
Server Network Utility) and then use JDBC SP3 to connect (and Java 5 Update
2), will the connection succeed? If the current version of Microsoft's JDBC
Driver for SQL Server won't make a SSL connection, are there plans on a
future version having this capability?
The reason I ask is because we have one application that uses JDBC to
connect to SQL Server and it has to use Microsoft's JDBC Driver in order to
work, so using a Type 3 JDBC driver isn't an option for us.
Thanks,
Jason
Why does your application have to use the MS driver? There are a lot of
commercial type 4 drivers out there and a pretty good open source one,
too. All of these support SSL.
Alin,
The jTDS Project.
|||Alin,
The application I'm referring to is a purchased application, and I believe
it is coded to use the Microsoft JDBC driver. At least that is what the
installation instructions lead me to believe.
Thanks,
Jason
"Alin Sinpalean" wrote:
> Why does your application have to use the MS driver? There are a lot of
> commercial type 4 drivers out there and a pretty good open source one,
> too. All of these support SSL.
> Alin,
> The jTDS Project.
>
|||Jason Delaune wrote:
> Alin,
> The application I'm referring to is a purchased application, and I
believe
> it is coded to use the Microsoft JDBC driver. At least that is what
the
> installation instructions lead me to believe.
Usually applications are coded to use the JDBC specification. Relying
on non-standard features of particular implementations is not a good
idea. If that's the case then you're out of luck.
You could still try another driver, though. In 90% of the cases it
works.
Alin.
|||Alin,
Which driver(s) would you recommend that supports connections to SQL Server
using SSL?
Thanks,
Jason
"Alin Sinpalean" wrote:
> Jason Delaune wrote:
> believe
> the
> Usually applications are coded to use the JDBC specification. Relying
> on non-standard features of particular implementations is not a good
> idea. If that's the case then you're out of luck.
> You could still try another driver, though. In 90% of the cases it
> works.
> Alin.
>
|||I would of course recommend the open source jTDS JDBC driver (which I'm
a developer of); you can get it from http://jtds.sourceforge.net
There are also quite a few commercial drivers out there if you don't
trust open source, but they do cost a lot and are not necessarily
better. Just do a Google search and they will turn up.
Alin,
The jTDS Project.
JDBC sample code using named pipe and SQLServer 2005 driver?
Hi,
Does anybody have a working Java code sample that connects to an SQLServer 2005 database on a remote host, via the default named pipe, from a client using the SQLServer 2005 JDBC driver? Could you post it, or a pointer to it?
I've gotten java.sql DriverManager.getConnection() to work fine with TCP/IP connections before. But I'm a newbie with named pipes, and unclear on how the connection string/properties are different. I've tried to piece it together from multiple docs and threads, but haven't found sample code that quite fits my situation. I think a simple working example would best clarify the syntax.
The server is not using SQL Express. Most SQLServer configuration options are defaults; the named pipes protocol is enabled.
Thanks
Hi Dan,
The Microsoft SQL Server 2005 JDBC Driver does not support connections over named pipes. It only supports TCP/IP connections.
--David Olix
|||David,Thanks for the info and your quick response.
I suggest mentioning this in the JDBC docs. I couldn't find it in my searching.
- Dan N.
Monday, February 20, 2012
JDBC Driver version to support SQL Server 2005 Database Mirroring
Hi
We are in the development phase of a project, which has SQL Server 2005 as the database, and Java for the presentation / business logic / services tiers. We are looking to increase resilience of the database tier and are intending to patch to service pack 1 and use the database mirroring facility. The advantages are quick failover which is important for this application. To implement this, what version of JDBC driver do we require? My concern is that although database mirroring is now supported in the database, we can't take advantage of it using Java?
Mark.
I think answer is here:http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=348327&SiteID=1
Thanks
JDBC Driver for Windows 2003 Server
MS SQL Server 2000 via the JDBC Driver Service Pack 2. I
upgraded my OS to Windows 2003 Server, but when i try to
connect to MS SQL Server via the same JDBC Driver, it
fails, i get error "Microsoft SQL Server 2000 Driver for
JDBC: Error establishing to socket".
What driver should i use to correct this? I dont see any
updated drivers available in microsoft.com.
thanks a lot!
tk wrote:
> I have a java application in Win2000 Server connecting to
> MS SQL Server 2000 via the JDBC Driver Service Pack 2. I
> upgraded my OS to Windows 2003 Server, but when i try to
> connect to MS SQL Server via the same JDBC Driver, it
> fails, i get error "Microsoft SQL Server 2000 Driver for
> JDBC: Error establishing to socket".
> What driver should i use to correct this? I dont see any
> updated drivers available in microsoft.com.
> thanks a lot!
Hi. It's not the driver. It's probably the DBMS not yet being configured
to listen in mixed-mode (listen for TCPIP connections). Got to setup and
check that.
Joe Weinstein at BEA
|||Hi,
I have a application in java using JDBC driver, but the connection is
correct and i have access to information.
In some cases a process of a user blocks the others, and until it is not
eliminated, they cannot continue the others. I would like to know as the
mixed-mode is configurated.
Thanks.
LuisJaimeG.
"Joe Weinstein" <joeNOSPAM@.bea.com> escribi en el mensaje
news:uzpgY9%23REHA.2876@.TK2MSFTNGP09.phx.gbl...
>
> tk wrote:
>
> Hi. It's not the driver. It's probably the DBMS not yet being configured
> to listen in mixed-mode (listen for TCPIP connections). Got to setup and
> check that.
> Joe Weinstein at BEA
>
|||solution please
************************************************** ********************
Sent via Fuzzy Software @. http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
|||| From: "Luis J." <ljgutierrez@.avansoft.com>
| References: <166b701c447c7$0cff79f0$a101280a@.phx.gbl>
<uzpgY9#REHA.2876@.TK2MSFTNGP09.phx.gbl>
| Subject: Re: JDBC Driver for Windows 2003 Server
| Date: Mon, 14 Jun 2004 23:48:57 -0500
| Lines: 40
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#fP4VPpUEHA.2844@.TK2MSFTNGP12.phx.gbl>
| Newsgroups: microsoft.public.sqlserver.jdbcdriver
| NNTP-Posting-Host: 200.124.170.10
| Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP12
.phx.gbl
| Xref: cpmsftngxa10.phx.gbl microsoft.public.sqlserver.jdbcdriver:6102
| X-Tomcat-NG: microsoft.public.sqlserver.jdbcdriver
|
| Hi,
|
| I have a application in java using JDBC driver, but the connection is
| correct and i have access to information.
|
| In some cases a process of a user blocks the others, and until it is not
| eliminated, they cannot continue the others. I would like to know as the
| mixed-mode is configurated.
|
| Thanks.
|
| LuisJaimeG.
Hi Luis,
Mixed mode authentication only matters when you are making your connection
to SQL Server. Once you're authenticated and connected, it no longer
applies. You can troubleshoot the blocking problem using the SQL Server
blocking script in conjunction with SQL Profiler.
271509 INF: How to Monitor SQL Server 2000 Blocking
http://support.microsoft.com/?id=271509
If you already know the SPID that is causing the blocking, you can simply
run "DBCC INPUTBUFFER(<spid>)" in Query Analyzer, where <spid> is your SPID
number. This will give you the SQL statement that is running at the time.
You can run "sp_lock" in Query Analyzer to see the specific locks that are
held by the blocking SPID. Once you identify which query is causing the
blocking, you can take steps to optimize the query (adding indexes,
recoding the query, etc). The faster the query executes, the less blocking
you will see. If the query is part of a transaction, you want to minimize
the size of your transactions to improve their speed and ultimately reduce
the blocking time.
Coding Efficient Transactions
http://msdn.microsoft.com/library/de...us/acdata/ac_8
_md_06_3eba.asp
Carb Simien, MCSE MCDBA MCAD
Microsoft Developer Support - Web Data
Please reply only to the newsgroups.
This posting is provided "AS IS" with no warranties, and confers no rights.
Are you secure? For information about the Strategic Technology Protection
Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.
|||tk wrote:
> I have a java application in Win2000 Server connecting to
> MS SQL Server 2000 via the JDBC Driver Service Pack 2. I
> upgraded my OS to Windows 2003 Server, but when i try to
> connect to MS SQL Server via the same JDBC Driver, it
> fails, i get error "Microsoft SQL Server 2000 Driver for
> JDBC: Error establishing to socket".
> What driver should i use to correct this? I dont see any
> updated drivers available in microsoft.com.
> thanks a lot!
Use netstat on the server to determine wether anyone is listening on the
SQL Server port.
You propably did not install SQL Server Service Pack 3.
On Windows 2003 Server TCP/IP is disabled for SQL Server without SP 3
due to security issues. Look at the eventlog, you will propably find a
message stating something in that direction.
Install SP 3, reboot and you should be fine.
Daniel Hagen
|||tk wrote:
> I have a java application in Win2000 Server connecting to
> MS SQL Server 2000 via the JDBC Driver Service Pack 2. I
> upgraded my OS to Windows 2003 Server, but when i try to
> connect to MS SQL Server via the same JDBC Driver, it
> fails, i get error "Microsoft SQL Server 2000 Driver for
> JDBC: Error establishing to socket".
> What driver should i use to correct this? I dont see any
> updated drivers available in microsoft.com.
> thanks a lot!
Use netstat on the server to determine wether anyone is listening on the
SQL Server port.
You propably did not install SQL Server Service Pack 3.
On Windows 2003 Server TCP/IP is disabled for SQL Server without SP 3
due to security issues. Look at the eventlog, you will propably find a
message stating something in that direction.
Install SP 3, reboot and you should be fine.
Daniel Hagen
|||I also upgraded from 2000 sever to 2003 server. My application was working fine with sql server until the upgrade. As a last resort I downloaded the Microsoft SQL Server 2000 Service Pack 3a and it did the trick. No more Error establishing socket connecti
on errors!
you can get the Service pack at:
http://www.microsoft.com/downloads/d...displaylang=en
I only installed the sql2ksp3.exe file.
Good Luck!
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.
JDBC driver for SQL Server 2000 and Java 5?
SQL Server 2000)? I need to upgrade my software to run on the latest Java
runtime soon...
Tim O'Konski wrote:
> How can I get a copy of an updated JDBC driver that works with Java 5
(for
> SQL Server 2000)? I need to upgrade my software to run on the latest
Java
> runtime soon...
Your old driver will work just fine with Java 5. Apart from a very
misterious _possible issue_ that noone knows nothing about:
http://groups-beta.google.com/group/...54c78ec924fc65
Alin.
|||Microsoft SQL Server 2000 Driver for JDBC SP3 has now been certified
against Java 1.5. We did not see any regression with the BigDecimal
issue.
-shelby
Shelby Goerlitz
Microsoft, SQL Server
"Alin Sinpalean" <alin@.earthling.net> wrote in message
news:alin@.earthling.net:
> Tim O'Konski wrote:
>
> (for
>
> Java
>
> Your old driver will work just fine with Java 5. Apart from a very
> misterious _possible issue_ that noone knows nothing about:
> http://groups-beta.google.com/group/...jdbcdriver/br
> owse_thread/thread/bc54c78ec924fc65
> Alin.