Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-19-2008, 10:34 AM
Member
 
Join Date: May 2008
Posts: 9
rmaadil is on a distinguished road
Connecting To SQL Server
Here is the code that I have written to get a connection to the SQL Server. I have also set the classpath. But still I am getting error. I have debugged the code and when I step over the Class.forName("com.microsoft.jdbc.sqlserver.SQLSer verDriver"); it generates an exception and the message that is printed is the string that is the parameter to the function forName. I am struck as I have searched a lot of forums and I haven't found this kind of error. Most of the errors that came due to classpath settings was "drievr cannot be found" but I think my error is not because of the classpath settings. Can anyone help me?

public class Main {


public static void main(String[] args) {

try
{

Class.forName("com.microsoft.jdbc.sqlserver.SQLSer verDriver");
Connection con = DriverManager.getConnection("jdbc:microsoft:sqlser ver://localhost:1433; DATABASENAME = Test","mimdad","aaa");
}
catch (Exception e)
{
System.out.println(e.getMessage());
}

}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-19-2008, 02:47 PM
Member
 
Join Date: Dec 2007
Posts: 32
felixtfelix is on a distinguished road
hi,

You have to add sqljdbc.jar to your classpath. That is the file which will connect with database with JDBC driver. Any queries please feel free.

Regards

Felix T
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-19-2008, 03:15 PM
Member
 
Join Date: May 2008
Posts: 9
rmaadil is on a distinguished road
I have used the following command in the command prompt to set the classpath but its not working yet. Help me ASAP

set classpath=C:\Program Files\Microsoft SQL Server 2005 JDBC Driver\sqljdbc_1.2\enu\sqljdbc.jar
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-19-2008, 03:35 PM
Member
 
Join Date: Dec 2007
Posts: 32
felixtfelix is on a distinguished road
Hi,

It seems that you are connecting with SQL SERVER 2000. So add the following three files to the class path

1.Add the follwing files in the classpath
1.msbase.jar
2.mssqlserver.jar
3.msutil.jar


Regards

Felix
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-19-2008, 05:00 PM
Member
 
Join Date: May 2008
Posts: 9
rmaadil is on a distinguished road
I am connecting with SQL Server 2005.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-19-2008, 05:57 PM
Member
 
Join Date: Dec 2007
Posts: 32
felixtfelix is on a distinguished road
hi,

Then you have to use the following DBDRIVER

com.microsoft.sqlserver.jdbc.SQLServerDriver

Regards
Felix
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-20-2008, 01:14 AM
erichua's Avatar
Member
 
Join Date: May 2008
Posts: 4
erichua is on a distinguished road
your driver name is strange, make sure your driver jar and the driver name are corret.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 08-20-2008, 07:53 PM
Member
 
Join Date: Aug 2008
Posts: 13
herfnai is on a distinguished road
hello you must make odbc and:
Connection cn=null;
Statement stm=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn=DriverManager.getConnection("jdbcdbc:database name");
stm=cn.createStatement(ResultSet.TYPE_SCROLL_SENSI TIVE,
ResultSet.CONCUR_UPDATABLE);
JOptionPane.showMessageDialog(null,"connected");

}catch(Exception e)
{JOptionPane.showMessageDialog(null,"eroor" +"\n"+e.getMessage());


}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Having problem in connecting with SQL Server 2005 rmaadil Database 4 05-21-2008 08:55 AM
Connecting to a Web server Java Tip java.net 0 04-07-2008 09:57 PM
Connecting to a database peiceonly New To Java 2 04-06-2008 04:28 PM
Java connecting to sql server 2005 pelegk2 Database 0 04-05-2008 11:17 PM
Who will know like connecting from Websphere Albert Enterprise JavaBeans 1 06-27-2007 05:41 PM


All times are GMT +3. The time now is 11:45 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org