与ssl

时间:2016-11-23 10:07:31

标签: java mysql hibernate jdbc

你好,我可以使用tcp / ip通过mysql workbench中的ssh连接远程数据库

但我无法连接java程序你可以给我回复我的代码在这里我要添加的内容请回复

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://192.168.1.10:3306/soa</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>

192.168.1.10远程数据库的ip地址 soa是数据库名称 根&amp; root是mysql的密码用户名和密码 3306默认端口

1 个答案:

答案 0 :(得分:0)

当您创建与URL的连接时,需要定义与您要使用的ssl键相关的一些属性。例如:

Properties props = new Properties();
props.setProperty("user", "root");
props.setProperty("password", "root");
props.setProperty("javax.net.ssl.trustStore",
"D:\\truststore\\truststore.jks");
props.setProperty("javax.net.ssl.trustStoreType","JKS");
props.setProperty("javax.net.ssl.trustStorePassword","welcome123");
Connection conn = DriverManager.getConnection(url, props); 
//your code

如果你正在使用休眠:

<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource">
    <property name="URL" value="jdbc:oracle:thin:@//host:port/service_name"/>
    <property name="user" value="root"/>
    <property name="password" value="root"/>
    <property name="maxPoolSize" value="10"/>
    <property name="initialPoolSize" value="5"/>
    <property name="connectionProperties>
        <value>
        oracle.net.ssl_cipher_suites: (ssl_rsa_export_with_rc4_40_md5, ssl_rsa_export_with_des40_cbc_sha)
        oracle.net.ssl_client_authentication: false
        oracle.net.ssl_version: 3.0
        oracle.net.encryption_client: REJECTED 
        oracle.net.crypto_checksum_client: REJECTED
        </value>
    </property>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <!-- classes etc -->
</bean>