简体   繁体   中英

mysql jdbc connection with ssl

hello i am able to connect remote database using tcp/ip over ssh through in mysql workbench

but i am unable to connect in java program can u give me reply my code is here what i have to add in that please reply

<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 address of remote database soa is database name root & root is password username and password of mysql 3306 default port

when you create the connection to your URL, need to define some properties related with the ssl key you are going to use. Example:

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

If you are using hibernate:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM