Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connecting to MSSQL2000

 
mohan kannan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to establish connection to mssql2000 on server through JSP
Server used is Tomcat
The code used in jsp is
//import required packages
<%@ page language="java" import="java.sql.*, java.io.*, java.util.*" %>
//urlformat one
String url="jdbc dbc snname;UID=username;PWD=password";
//url format two
//String url="jdbc dbc snname";
Connection con=null;;
try
{
// Load Driver.
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
out.println("JDBC Driver Loaded");

}
catch (Exception le)
{
out.println( "Error Number.1 : Could not Load JdbcOdbcDriver."+le.getMessage());
}

try
{
// Connect to database.
//connect using url format one
con= DriverManager.getConnection(url);
//connect using url format two
// con= DriverManager.getConnection(url,"username","password");
out.println("Connected to database");

catch (SQLException cnfe)
{
out.println( "Error Number. 2 : SQLException: Could not connect to dB\r\n");

out.println( "Error Message is "+cnfe.getMessage() + "\r\n");

out.println( "Error Code is " +cnfe.getErrorCode());
out.println( "Error State is "+cnfe.getSQLState() + "\r\n");
}
catch (Exception e)
{
out.println( "Error No. 3 : Exception: An unknown error occurred while connecting to DB."+e.getMessage());

}
It's loading the driver and "JDBC Driver Loaded " message received
I have properly replaced dsnname, username and password in url string with the exact dsn details provided by
my system administrator.
But when trying to get connection the server output is
Hello loading and connecting to dB
JDBC Driver Loaded
Error Number. 2 : SQLException: Could not connect to dB
Error Message is [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Error Code is 0
Error State is IM002
The above error received for the both url formats
The same code /jsp file when run on local machine (mssql7 and tomcat 4.0.1) with the same dsn name properly configured
(Here I used user name="sa" and password="") is able to establish connection to database.
System administrator says that the dsn is configured properly on the server.
Please indicate whether the problem is with the code or the dsn is not properly configured at the server
thanks in advance
Mohan
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mohan kannan:
Data source name not found and no default driver specified

Hi,
have you made the ODBC DSN.. and is it in System DSN.. Make sure all the configuration properties..
I think here the problem lies..
Pranit..
 
mohan kannan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi pranik
Thanks for yr reply
My situation is I cannot access dsn configuration since the server is at USA
and it is a bought out space.
The system administrator claims that dsn is configured properly.
So all I want confirm is whether the problem is with the code or he (admin) claim is wrong
Thanks
Mohan
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mohan,
I don't find any problem in your code, assuming u've typed the dsn correctly.. It seems to be your Sys admin is doing somethng wrong..
BTW, Can you please tell me the hosting provider name.. bcoz, i've developed a site in Java and SQL server.. i m searching for a provider of that configuration.. But i m getting everybody with mysql.. please give me the details regarding the provider in pranitsaha@hotmail.com ..
Thanks in advance..
Pranit..
 
mohan kannan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pranit
Thanks for your mail
I took the space from www.hostingbizz.com
They provide java space on win2000 os with tomcat
provides servlet/jsp contanier service

Also http://mx-solutions.com/ provide java space
on winnt os with mssql dB. I am not sure of their's java server (ie whether tomcat or jrun)
Thanks
Mohan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic