[selenium-users] Sel RC:How to access data Base using MS SQL Server from Eclipse?

194 views
Skip to first unread message

Kuntal

unread,
Apr 21, 2010, 3:49:58 AM4/21/10
to Selenium Users
Hi All,
I want to retrieve some values from Database to Eclipse.
I am using the MS SQL 2005 Server for DBMS.
Here I added the MS SQL Jdbc Driver 1 and wrote the following code to
access the DB.
I am retrieving some values from DB and want to display it in Java
console.

Code is :

package package1;
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.*;
import org.testng.*;
import java.sql.*;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.io.*;
import sun.jdbc.odbc.*;


import java.sql.*;
import javax.naming.*;
import javax.sql.*;



public class DatabaseTesting
{
public static void main(String args[]) throws
ClassNotFoundException, SQLException{

//See your driver documentation for the proper format of this
string :
String DB_CONN_STRING = "jdbc:sqlserver://
192.168.1.180:1433;DatabaseName=TEST_DB";
//Provided by your driver documentation. In this case, a MySql
driver is used :
String DRIVER_CLASS_NAME =
"com.microsoft.jdbc.sqlserver.SQLServerDrive";
String USER_NAME = "username";
String PASSWORD = "password";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection connection = null;

connection = DriverManager.getConnection(DB_CONN_STRING,
USER_NAME, PASSWORD);

//Statement stmt=null;


try{
Statement stmt = connection.createStatement();
ResultSet result = stmt.executeQuery("select top 1
email_address from user_register_table'");
String emailaddress= result.getString("email_address");
System.out.println(emailaddress);

}
catch (SQLException e){
System.out.println("Exception3");

//log( "Driver loaded, but cannot connect to db: " +
DB_CONN_STRING);
}


}

}

But, I am always getting the Error message :
seleniumException in thread "main"
com.microsoft.sqlserver.jdbc.SQLServerException: The TDS prelogin
response is incomplete. The target server must be SQL Server 2000 or
later.
at
com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown
Source)
at com.microsoft.sqlserver.jdbc.DBComms.Prelogin(Unknown Source)
at com.microsoft.sqlserver.jdbc.DBComms.<init>(Unknown Source)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown
Source)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown
Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at package1.DatabaseTesting.main(DatabaseTesting.java:36)

I am unable to make out the reason for the Error message.
Any Help would be highly appreciated.

Regards,
Kuntal

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.

Reply all
Reply to author
Forward
0 new messages