使用SSH开发JavaWeb应用,怎样连接到网络数据库?

如题,我在阿里云上开了一个数据库RDS,在本地开发时配置Hibernate如下:

     <!-- 数据库连接设置 -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <!-- 技术:数据库类型:服务器ip/数据库名 -->
        <property name="connection.url">jdbc:mysql://我的服务器ip地址:3001/mywebset</property>
        <property name="connection.username">root</property>
        <property name="connection.password">Li774717903</property>

        <!-- 配置dialect方言,明确告诉hibernate连接的是哪种数据库 -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

端口、数据库名、用户名、密码都是正确的,但是在访问数据库时报错,错误发生在我的HibernateUtil类中:

     HibernateUtil() {
            sessionFactory = new Configuration().configure().buildSessionFactory();//此处报错
        System.out.println("HibernateUtil : 连接成功");
    }

我想知道连接网络上的数据库需要怎样配置?

部分错误信息如下:

     Type Exception Report

    Message Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

    Description The server encountered an unexpected condition that prevented it from fulfilling the request.

    Exception

    org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
    org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:267)
    org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:231)
    org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
    org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
    org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
    org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:240)
    org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
    org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
    org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
    org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
    org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
    org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
    org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
    org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
    com.hibernate.dao.HibernateUtil.<init>(HibernateUtil.java:13)
    com.hibernate.dao.MusicDao.getAll(MusicDao.java:61)
    com.struts.action.IndexAction.toMusic(IndexAction.java:36)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:498)
    com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:450)
    com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:289)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:252)
    org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)

1个回答

建议你咨询阿里云客服,他们会告诉你数据库的配置,比如端口、防火墙如何设置。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问

相似问题