Please start any new threads on our new 
    site at https://forums.sqlteam.com.  We've got lots of great SQL Server
    experts to answer whatever question you can come up with.
    
        | 
                
                    | 
                            
                                | Author | Topic |  
                                    | AskSQLTeamAsk SQLTeam Question
 
 
                                        0 Posts | 
                                            
                                            |  Posted - 2004-06-21 : 11:25:05 
 |  
                                            | Dan writes "I am running Windows XP and SQL Server 2000.I want to query a database in my SQL Server 2000 application from within Java.So far I have successfully connected to SQL Server using a SQLServerDriver:Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");String connUrl = "jdbc:microsoft:sqlserver://<hostname>:<port>";conn = DriverManager.getConnection(connUrl, "<user>", "<pass>"); This code allows me to connect to the master database within SQL Server 2000 and I have been able to query the master database successfully.My question is: How can I connect to a different database within SQL Server 2000 and then query it?I tried looking for the answer to this in the FAQ but had no luck. Thanks in advance for your assistance" |  |  
                                    | chadmatThe Chadinator
 
 
                                    1974 Posts | 
                                        
                                          |  Posted - 2004-06-21 : 17:05:23 
 |  
                                          | I'm not real familiar with Java, however, the Connection String should allow you to specify "Catalog" which is the DB you want to use.  Or you could put USE MyDB GOin your SQL code.-Chadhttp://www.clrsoft.comSoftware built for the Common Language Runtime. |  
                                          |  |  |  
                                    | AndraaxAged Yak Warrior
 
 
                                    790 Posts | 
                                        
                                          |  Posted - 2004-06-22 : 02:04:27 
 |  
                                          | Hi!Use the following format:Connection conn = DriverManager.getConnection ("jdbc:microsoft:sqlserver://server1:1433;User=test;Password=secret;DatabaseName=Northwind");All the connection properties are in the help file if you have it./Andraax |  
                                          |  |  |  
                                |  |  |  |