Java Driver problem

I'm using SQL server 2000(Standard) on Microsoft windows 2003 machine. I'm using Tomcat server 4.1 and I use the following string to connect

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");

String str="jdbc:microsoft:sqlserver://10.11.1.216:1433;SelectMethod=cursor;DatabaseName=GH";

Connection con = DriverManager.getConnection(str,"ghisro","ghisro");

My application is working fine.

But in another PC based(XP machine), I'm loading SQL server(Personal Edition) and same Tomcat 4.1. Instead of 10.11.1.216:1433, I've used localhost. But I'm not getting connection. What cud be the problem?

[647 byte] By [harinibiligiria] at [2007-11-27 11:41:16]
# 1

Did you use localhost or loaclhost:1433? The 1433 is the port number and needs to be provided.

tolmanka at 2007-7-29 17:37:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

If no port number is supplied for SQL Server, then the default port of 1433 will be used. That is not the issue.

But you said that the SQL server is installed in a 2003 machine and that you're trying to accessing it from a XP machine using the hostname 'localhost' ? Do you understand the meaning of hostnames and IP addresses and especially the meaning of 'localhost' ? Why are you using localhost instead of the real hostname or IP address of the server?

BalusCa at 2007-7-29 17:37:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

I know what IP addresses and localhost means. Probably u've not got my question clearly. There r two scenarios

1) SQL server 2000(standard edition) is on windows 2000 server(say X). Tomcat 4.1 is running on one more windows 2000 server(say B). My jsp programs are residing in the server B. There I'm using the connection this connection string and my application is running properly.

Now one requirment has come where in my application has to run in a standalone mode. Here there is only one machine with windows XP loaded in it. Here I've loaded SQL server 2000(Personal edition) and Tomcat 4.1 in the same machine. Since the SQL server is on the same machine I need to specify it as a localhost. But I'm not getting connection. Here is the problem.

harinibiligiria at 2007-7-29 17:37:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

OK. Which exception exactly are you getting?

BalusCa at 2007-7-29 17:37:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

This is the exception

Exception occured while connecting to Database. Try later ....

java.lang.ArrayIndexOutOfBoundsException: -1

harinibiligiria at 2007-7-29 17:37:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

http://www.google.com/search?q=java.lang.ArrayIndexOutOfBoundsException+sql+server+jdbc

Upgrade your driver.

BalusCa at 2007-7-29 17:37:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

I've changed my driver.

Class.forName("net.sourceforge.jtds.jdbc.Driver");

String str="jdbc:jtds:sqlserver//127.0.0.1:1433/GH";

Connection con = DriverManager.getConnection(str,"ghisro","ghisro");

Through query analyser, I can connect to database with ghisro.

Thro my application, still I'm getting the following error.

java.lang.ArrayIndexOutOfBoundsException: -1

harinibiligiria at 2007-7-29 17:37:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

check if the values returned by you DB is of say size as of array if u have any.

This exception is due to the array size small than the number of elements that needs to be in it.

or copy past ur code here

hetal_giria at 2007-7-29 17:37:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

And the complete stacktrace. At least the line where this exception is thrown.

BalusCa at 2007-7-29 17:37:09 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...