Avatar of Mark
Mark
 asked on

trouble connecting with Microsoft jdbc driver

I have a strange problem. I've set up a new tomcat installation on a new Linux Slackware computer. I am doing the following:

try {
  Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  con = DriverManager.getConnection(jdbc:sqlserver://sqlhost\\instance:1433;loginTimeout=10;user=myuser;password=mypass;");
}
catch (SQLExceltion e) { .... }

This works just fine in serveral java programs I have written on this machine, but when I use this in jsp I get an exception. e.getErrorCode() is zero; e.getMessage() is ""cantleys: cantleys: Name or service not known"

I am at a loss about this error. I have successfully installed java and tomcat on three other Linux hosts w/o this problem. "cantleys" is the hostname of this Linux computer. Why is it mentioning it as a service name? Why does this only happen with jsp but not regular java?

I am using the same tomcat version and same sqljdbc.jar on all machines. I've put the sqljdbc.jar file in .../webapps/myapp/WEB-INF/lib and in $CATALINA_HOME/lib, and it both places at once, no difference. If I remove the sqljdbc.jar file from these libs I get java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver, so I know it is using the correct jarfile.
 
This is killing me! I've been messing with it for hours and comparing with the other computers. Help! I've got a deadline!!!

THX
JSPMicrosoft SQL Server 2005Java

Avatar of undefined
Last Comment
Mark

8/22/2022 - Mon
SOLUTION
Am P

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
CEHJ

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Mark

ASKER
amit_n_panchal: yes, the etc/hosts files are all different, but are all at different locations. None are in the same domain.

CEHJ: "I'm assuming those are obscured versions of what you really have there"

Yes, obscured. "sqlhost", "instance", "myuser", and "mypass" are fake, but otherwise the connection URL is exactly as I've shown.

Here's the thing that I must not have made clear enough. On this very same host I can write java programs that connect to the database just fine. The sqljdbc.jar in the CLASSPATH is the exact same jarfile used by tomcat. The connection URL used by the java program is exactly the same one used by the jsp programs (I printed them both out). Port 1433 work fine for the java programs. Plus, I know from experience that there is a different message if the right port is not opened.

The only think I can think of that is different is that tomcat is "running" the jsp programs; or is somehow involved (or in this case interferring). Can you think of a config setting that might be causing a problem? Does it need some additional port on the SQL Server host?

I just set this whole thing up on another Linux machine a few weeks ago and I've essentially copied the tomcat hierarchy to the new machine. The difference between the machines are the local hostname, the target SQL Server and the connection URL. The problem's gotta be somewhere in that nexus (but don't let me stifle imagination!)

Like I said, plain 'ole java programs work fine connecting (a command path issue?)


The ONLY difference
Mark

ASKER
more info: I've redirected the connection URL to point to a friend's SQL Server host across town, and visa versa: redirected his connection URL to point to my SQL Server host.

I can query from the friend's workstation to my database both at the java/command-line level AND via jsp.

I can query from my computer to my friend's SQL Server at the java/command-line level, but NOT via jsp. Yet he, of course, can query from his own computer to his own SQL Server with BOTH java/command-line and jsp.

I think this eliminates my SQL Server as being the problem.

My computer is a more-or-less clone of his for setup of java, tomcat, apache, etc., etc. (in fact, I set up his computer too!) HOWEVER, there must be something different with my config that prevents tomcat/jsp from connecting to either my SQL Server or his SQL server.

Any ideas where to look? Meanwhile, I will embark on a file-by-file, line-by-line comparison of all things tomcat.
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
CEHJ

:) Glad you fixed it
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Mark

ASKER
points for the effort.