1
<property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://localhost/my_db"/>
<property name="javax.persistence.jdbc.user" value=""/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<property name="hibernate.show_sql" value="true"/>

I am trying to connect to my local sql server by using this piece of configurating above. Mysql, oracle and postgresql work fine wtihout any problem but I do not really know how to connect to sql server since I have neither username nor password for it. I wrote something like this. "Data Source=myserver;Initial Catalog=mydb;Integrated Security=SSPI". How do I achieve this or anoher way to connect my localhost for sql server? Thanks

4
  • what do you mean with since I have neither username nor password for it. ?! You can't connect to a db without user and pass Commented Jul 20, 2018 at 6:56
  • I only write my computers name and database name to connect it. I think windows authentication just let me in Commented Jul 20, 2018 at 7:00
  • @Leviand Are you aware that Microsoft SQL Server JDBC driver has support for Windows/Kerberos authentication which means you can connect without specifying a username and password (it will use the credentials of the user running the current process). Commented Jul 20, 2018 at 14:49
  • Yeah but its way better use a dedicated user imho... Commented Jul 20, 2018 at 17:09

1 Answer 1

1

In order to connect to the SQL Server instance using Windows authentication you need to add integratedSecurity=true to your connection URL, e.g.,

jdbc:sqlserver://localhost:49242;databaseName=myDb;integratedSecurity=true

You also need to ensure that the file "sqljdbc_auth.dll" can be found on the library path for your Java application. (One way to do that is to ensure that its location is included in the Windows PATH environment variable.)

Sign up to request clarification or add additional context in comments.

1 Comment

The alternative Kerberos authentication does not need the native library, see learn.microsoft.com/en-us/sql/connect/jdbc/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.