This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hi, I am confused about the syntax of getConnection() method. Can anyone tell me what's wrong with the following syntax? My databasename, username and password is "CC". And my database is on the local machine.
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433/CC","CC","CC");
the method usage seesm to be correct. can you please post the exeception that program raise ? by using the exception users will be able to help you about your problem.
Hi, The following is the exception. ---------------------------------------------- java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Unable to conn ect. Invalid URL. at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source ) at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source) at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source) at java.sql.DriverManager.getConnection(DriverManager.java:512) at java.sql.DriverManager.getConnection(DriverManager.java:171) at UBDAO.main(UBDAO.java:41) Error Trace in getConnection() : [Microsoft][SQLServer 2000 Driver for JDBC]Unab le to connect. Invalid URL. ------------------------------------------------------------------------
The problem is with the syntax where I am giving the database name. There's no problem with the authentication to the database since the same database, username and password is working fine if I pass the paramenter as a string to this getConnection() method as follows. --------------------------------------------- import java.io.*; import java.sql.*;
public class UBDAO { private java.sql.Connection con = null; private final String url = "jdbc:microsoft:sqlserver://"; private final String serverName= "localhost"; private final String portNumber = "1433"; private final String databaseName= "CC"; private final String userName = "CC"; private final String password = "CC";
DSN-->DSN name you have used while creating DSN as mentioned below. un-->user name for the sql server. pwd-->password for the sql server.
You might have to create a Data Source Name(DSN) by going to ControlPanel-->Administrative Tools-->DataSources(ODBC) and click add to create the DSN and follow on.Hope this might help you. [ May 23, 2006: Message edited by: Vishwanath Rajashekar ]
stu derby
Ranch Hand
Joined: Dec 15, 2005
Posts: 333
posted
0
Originally posted by Vishwanath Rajashekar: class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
If you're using the native type IV drivers for SQL Server, as the original poster is trying to do, then you most certainly don't want to use a DSN and the JDBC-ODBC bridge. For many purposes, the briddge has some insurmountable problems, not least of which is the lack of support for concurrent usage in multi-threaded programs.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.