java - Connecting to database using hibernate - connection url -


i trying connect database using hibernate, have read documentation , user guild still cannot connect database. steps took:

  1. adding relevant hibernate jars , sqljdbc41.jar (sql server jdbc driver) project.
  2. added xml following sqljdbc_auth.dll (x64) environment path.
  3. created xml name hibernate.cfg.xml following connection , dialect:

        <!-- database connection settings --> <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.sqlserverdriver</property> <property name="hibernate.connection.url">"jdbc:sqlserver://localhost;databasename=forumsystem;integratedsecurity=true;"</property>  <!-- sql dialect --> <property name="hibernate.dialect">org.hibernate.dialect.sqlserverdialect</property> 

as can see server local , using windows authentication, did not change defualt instance , port.

i try connection databse using following code:

 configuration configuration = new configuration();     configuration.configure();     serviceregistry = new standardserviceregistrybuilder().applysettings(             configuration.getproperties()).build();     sessionfactory = configuration.buildsessionfactory(serviceregistry); 

and following error:

exception in thread "main" org.hibernate.hibernateexception: unable make jdbc connection ["jdbc:sqlserver://shperb;databasename=forumsystem;integratedsecurity=true;"] 

i have tried modify connection url include port , instance name anyway , tried connect without windows authentication made no progress.

have missed something? there way know of parameters wrong?

edit: forgot mention tcp\ip enabled in sql server configuration , allow both windows authentication , sql authentication in database. if try connect using:

string connectionurl = "jdbc:sqlserver://shperb;database=forumsystem;integratedsecurity=true;"; connection con = drivermanager.getconnection(connectionurl); 

it works, not using hibernate

try add jdbc:microsoft:sqlserver in url. yoou need specify driver microsoft sql jdbc driver. see more connecting ms sql through hibernate , how configure hibernate config file sql server

also check whether custom port set , add connection params.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -