locked
Cant connect to Azure database RRS feed

  • Question

  • Here I am new to Azure and I cant connect to the database. It worked fine on mysql. I have a feeling it has to do with my connection settings. Below is the error I am getting. I am using hibernate 

    May 27, 2018 4:34:43 PM org.hibernate.Version logVersion
    INFO: HHH000412: Hibernate Core {5.3.0.Beta1}
    May 27, 2018 4:34:43 PM org.hibernate.cfg.Environment <clinit>
    INFO: HHH000206: hibernate.properties not found
    May 27, 2018 4:34:43 PM org.hibernate.boot.jaxb.internal.stax.LocalXmlResourceResolver resolveEntity
    WARN: HHH90000012: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/hibernate-configuration. Use namespace http://www.hibernate.org/dtd/hibernate-configuration instead.  Support for obsolete DTD/XSD namespaces may be removed at any time.
    May 27, 2018 4:34:44 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
    INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
    May 27, 2018 4:34:45 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
    Exception in thread "AWT-EventQueue-0" java.lang.ExceptionInInitializerError
    	at dao.SEDAOImpl.getEntities(SEDAOImpl.java:33)
    	at service.SEService.getEntities(SEService.java:27)
    	at gui.StudentGUI.getStudents(StudentGUI.java:155)
    	at gui.StudentGUI.buildTable(StudentGUI.java:142)
    	at main.Main_GUI.view(Main_GUI.java:174)
    	at main.Main_GUI.lambda$1(Main_GUI.java:84)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.AbstractButton.doClick(Unknown Source)
    	at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
    	at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$500(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.awt.EventQueue$3.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.awt.EventQueue$4.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
    	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:270)
    	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:232)
    	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:209)
    	at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
    	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
    	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:241)
    	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:209)
    	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:356)
    	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:112)
    	at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:84)
    	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:470)
    	at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:91)
    	at org.hibernate.boot.MetadataSources.buildMetadata(MetadataSources.java:179)
    	at util.HibernateUtil.<init>(HibernateUtil.java:19)
    	at util.HibernateUtil.<clinit>(HibernateUtil.java:11)
    	... 44 more
    Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [>com.microsoft.sqlserver.jdbc.SQLServerDriver]
    	at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:348)
    	at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.loadDriverIfPossible(DriverManagerConnectionProviderImpl.java:163)
    	at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildCreator(DriverManagerConnectionProviderImpl.java:119)
    	at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildPool(DriverManagerConnectionProviderImpl.java:103)
    	at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:75)
    	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
    	at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:241)
    	at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:209)
    	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145)
    	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66)
    	at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
    	at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
    	at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:258)
    	... 58 more
    Caused by: java.lang.ClassNotFoundException: Could not load requested class : >com.microsoft.sqlserver.jdbc.SQLServerDriver
    	at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:336)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Unknown Source)
    	at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:345)
    	... 70 more

    Here is my connection

    <hibernate-configuration>
    	<session-factory>
    		<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    		<property name="hibernate.connection.driver_class">>com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
    		<property name="hibernate.connection.url">jdbc:mysql://sedb.mysql.database.azure.com:3306; </property>
    		<property name="hibernate.connection.username">sefinal</property>
    		<property name="hibernate.connection.password">5Mccartney@</property>
    		<property name="hibernate.show_sql">true</property>
    		<property name="hibernate.hbm2ddl.auto">update</property>
    
    
    
    		<mapping class="model.Student"/>
    		<mapping class="model.Course"/>
    		<mapping class="model.Department"/>
    		<mapping class="model.Professor"/>
    		<mapping class="model.Enroll"/>
    	</session-factory>
    </hibernate-configuration>

    DB info:


    • <label aria-hidden="true" class="msportalfx-property-name fxs-portal-title msportalfx-tooltip-overflow fxs-part-properties-text" data-bind="text: label, attr: {id: "azc-label-" + $root.randomId + "-" + $index() }" id="azc-label-3249008b-951a-45ea-ba8c-14b8647a604e-1" style="font-size:11px;font-weight:inherit;vertical-align:top;margin-color:#444444;line-height:normal;width:auto;text-max-width:100%;display:inline-block;flex:0 1 auto;white-space:nowrap;">Server name</label>
      sedb.mysql.database.azure
    • <label aria-hidden="true" class="msportalfx-property-name fxs-portal-title msportalfx-tooltip-overflow fxs-part-properties-text" data-bind="text: label, attr: {id: "azc-label-" + $root.randomId + "-" + $index() }" id="azc-label-3249008b-951a-45ea-ba8c-14b8647a604e-2" style="font-size:11px;font-weight:inherit;vertical-align:top;margin-color:#444444;line-height:normal;width:auto;text-max-width:100%;display:inline-block;flex:0 1 auto;white-space:nowrap;">Status</label>
      Available
    • <label aria-hidden="true" class="msportalfx-property-name fxs-portal-title msportalfx-tooltip-overflow fxs-part-properties-text" data-bind="text: label, attr: {id: "azc-label-" + $root.randomId + "-" + $index() }" id="azc-label-3249008b-951a-45ea-ba8c-14b8647a604e-3" style="font-size:11px;font-weight:inherit;vertical-align:top;margin-color:#444444;line-height:normal;width:auto;text-max-width:100%;display:inline-block;flex:0 1 auto;white-space:nowrap;">Server admin login name</label>
      sefinal@sedb
    • <label aria-hidden="true" class="msportalfx-property-name fxs-portal-title msportalfx-tooltip-overflow fxs-part-properties-text" data-bind="text: label, attr: {id: "azc-label-" + $root.randomId + "-" + $index() }" id="azc-label-3249008b-951a-45ea-ba8c-14b8647a604e-4" style="font-size:11px;font-weight:inherit;vertical-align:top;margin-color:#444444;line-height:normal;width:auto;text-max-width:100%;display:inline-block;flex:0 1 auto;white-space:nowrap;">Location</label>
      West US
    • <label aria-hidden="true" class="msportalfx-property-name fxs-portal-title msportalfx-tooltip-overflow fxs-part-properties-text" data-bind="text: label, attr: {id: "azc-label-" + $root.randomId + "-" + $index() }" id="azc-label-3249008b-951a-45ea-ba8c-14b8647a604e-5" style="font-size:11px;font-weight:inherit;vertical-align:top;margin-color:#444444;line-height:normal;width:auto;text-max-width:100%;display:inline-block;flex:0 1 auto;white-space:nowrap;">MySQL version</label>
      5.7
    • <label aria-hidden="true" class="msportalfx-property-name fxs-portal-title msportalfx-tooltip-overflow fxs-part-properties-openbladeasync" data-bind="text: label, attr: {id: "azc-label-" + $root.randomId + "-" + $index() }" id="azc-label-3249008b-951a-45ea-ba8c-14b8647a604e-6" style="font-size:11px;font-weight:inherit;vertical-align:top;margin-color:#444444;line-height:normal;width:auto;text-max-width:100%;display:inline-block;flex:0 1 auto;white-space:nowrap;">S</label>



    • Edited by lawcrens1 Sunday, May 27, 2018 11:48 PM
    Sunday, May 27, 2018 11:41 PM

All replies

  • Hi, 

    I can't seem to see the database info you included in your post. Can you please share it again? 

    Also, can you please clarify if you're connecting to a server in Azure Database for MySQL or Azure SQL Database? 

    Thanks,

    Andrea Lam 

    Program Manager, Azure Data

    Wednesday, May 30, 2018 12:54 AM
  • Here is the vanilla JDBC connection string for Azure Database for MySQL: 

    String url ="jdbc:mysql://{host_name}:3306/{your_database}?useSSL=true&requireSSL=false"; myDbConn = DriverManager.getConnection(url, "{your_username}", {your_password});

    Here is some specific information in regard to troubleshooting this issue: Connection mySQL and hibernate problems

    Regards,

    Mike

    Thursday, May 31, 2018 6:31 PM
  • Looking at your properties, it seems like you are using the JDBC Driver for SQL Server to connect to MySQL.

    <property name="hibernate.connection.driver_class">>com.microsoft.sqlserver.jdbc.SQLServerDriver</property> 


    Please try to use the JDBC Driver for MySQL instead. This can be obtained from Maven Central or the MySQL download page


    Thursday, May 31, 2018 8:39 PM