• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connecting to SQL Server results in error

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic