Results 1 to 8 of 8
Thread: Connecting To SQL Server
- 05-19-2008, 08:34 AM #1
Member
- Join Date
- May 2008
- Posts
- 9
- Rep Power
- 0
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());
}
}
}
- 05-19-2008, 12:47 PM #2
Member
- Join Date
- Dec 2007
- Location
- Mumbai, India
- Posts
- 37
- Rep Power
- 0
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
- 05-19-2008, 01:15 PM #3
Member
- Join Date
- May 2008
- Posts
- 9
- Rep Power
- 0
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
- 05-19-2008, 01:35 PM #4
Member
- Join Date
- Dec 2007
- Location
- Mumbai, India
- Posts
- 37
- Rep Power
- 0
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
- 05-19-2008, 03:00 PM #5
Member
- Join Date
- May 2008
- Posts
- 9
- Rep Power
- 0
I am connecting with SQL Server 2005.
- 05-19-2008, 03:57 PM #6
Member
- Join Date
- Dec 2007
- Location
- Mumbai, India
- Posts
- 37
- Rep Power
- 0
hi,
Then you have to use the following DBDRIVER
com.microsoft.sqlserver.jdbc.SQLServerDriver
Regards
Felix
- 05-19-2008, 11:14 PM #7
your driver name is strange, make sure your driver jar and the driver name are corret.
- 08-20-2008, 05:53 PM #8
Member
- Join Date
- Aug 2008
- Posts
- 13
- Rep Power
- 0
hello you must make odbc and:
Connection cn=null;
Statement stm=null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
cn=DriverManager.getConnection("jdbc:odbc: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());
}
Similar Threads
-
Having problem in connecting with SQL Server 2005
By rmaadil in forum JDBCReplies: 4Last Post: 05-21-2008, 06:55 AM -
Connecting to a Web server
By Java Tip in forum java.netReplies: 0Last Post: 04-07-2008, 07:57 PM -
Connecting to a database
By peiceonly in forum New To JavaReplies: 2Last Post: 04-06-2008, 02:28 PM -
Java connecting to sql server 2005
By pelegk2 in forum JDBCReplies: 0Last Post: 04-05-2008, 09:17 PM -
Who will know like connecting from Websphere
By Albert in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 06-27-2007, 03:41 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks