• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using SQL Server database with JDBC. Need Help.

 
Jeff Schuler
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm an rookie with regards to using databases with JDBC. I downloaded the JDBC driver for Microsoft SQL Server and I was able to register the driver using this statement:



I don't get any errors with the above line but I'm unsure how to open up a database connection. I used Windows Authentication when creating a database in MS SQL Server, so I didn't use a name or password. I tried a lot of things but couldn't get a connection. Can someone please provide an example how I would connect to the database?

Questions:
Since I didn't use a name and password when creating the database, can I connect without a name and password?
How does it know where the database exists on my system?

Here are several things that I tried:
"jdbc:datadirect:sqlserver://server1:1433;databaseName=Jeff;AuthenticationMethod=auto";" "jdbc:sqlserver://localhost:1433;databaseName=Jeff;user=mySystemUsername;password=mySystemPassword";
"jdbc:datadirect:sqlserver://server1:1433;AuthenticationMethod=auto";"

When I run the getConnection method I get unsuitable driver for the first example and a TCP/IP error on the second.

TIA
 
Marilyn de Queiroz
Sheriff
Posts: 9068
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Questions:
Since I didn't use a name and password when creating the database, can I connect without a name and password?


yes

Try the getConnection() method using something like this:

Connection con = DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost:1433/Jeff");
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic