Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Connecting to SQL Server results in error

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am unable to connect to sql server, getting following error.

exception com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection
to the host SSALES, port 1433 has failed. Error: "The driver received an unexpe
cted pre-login response. Verify the connection properties and check that an inst
ance of SQL Server is running on the host and accepting TCP/IP connections at th
e port. This driver can be used only with SQL Server 2000 or later.".

**my local Environment:-**

java 5,
sql server enterprise manager version 8,
OS- window server 2003



**RunApp.java**

   Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
   conn = java.sql.DriverManager.getConnection("jdbc:sqlserver://abc;d‌​atabaseName={db};use‌​r=name;password=pass‌​worf;");
   Statement stmt=conn.createStatement();  
   ResultSet rs=stmt.executeQuery("SELECT * FROM testdb.testtabel where active = 'a'");

**running through cmd:**

   set path="C:\Program Files\Java\jdk5\bin";
   
   javac -classpath "D:\Web Development\ABC\lib\mail-1.4.3.jar;D:\Web Development\ABC\lib\sqljdbc.jar;" com\test\RunApp.java
   
   java -classpath "D:\Web Development\ABC\lib\mail-1.4.3.jar;D:\Web Development\ABC\lib\sqljdbc.jar;" com.test.RunApp
   

 
author
Posts: 23878
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Let's move this topic to the JDBC forum, as the Ranch Office forum is for the discussion of the ranch itself.

And welcome to the ranch,
Henry
 
Bartender
Posts: 1752
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

chethan hs wrote:I am unable to connect to sql server, getting following error.

exception com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection
to the host SSALES, port 1433 has failed. Error: "The driver received an unexpe
cted pre-login response. Verify the connection properties and check that an inst
ance of SQL Server is running on the host and accepting TCP/IP connections at th
e port. This driver can be used only with SQL Server 2000 or later.".

**my local Environment:-**

java 5,
sql server enterprise manager version 8,
OS- window server 2003

**RunApp.java**

   Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
   conn = java.sql.DriverManager.getConnection("jdbc:sqlserver://abc;d‌​atabaseName={db};use‌​r=name;password=pass‌​worf;");
   Statement stmt=conn.createStatement();  
   ResultSet rs=stmt.executeQuery("SELECT * FROM testdb.testtabel where active = 'a'");

**running through cmd:**

   set path="C:\Program Files\Java\jdk5\bin";
   
   javac -classpath "D:\Web Development\ABC\lib\mail-1.4.3.jar;D:\Web Development\ABC\lib\sqljdbc.jar;" com\test\RunApp.java
   
   java -classpath "D:\Web Development\ABC\lib\mail-1.4.3.jar;D:\Web Development\ABC\lib\sqljdbc.jar;" com.test.RunApp
   



From part of the error message above, it looks like that you're not using the correct driver for the version of SQL Server you have.

This information might help: https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774

- mike
 
Ranch Hand
Posts: 180
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try with this code...


It works for me...
follow is my compiled result !

run:
Connecting to database...
BUILD SUCCESSFUL (total time: 0 seconds)
 
    Bookmark Topic Watch Topic
  • New Topic