gpt4 book ai didi

java - mysql jdbc与ssl连接

转载 作者:行者123 更新时间:2023-11-29 19:53:22 24 4
gpt4 key购买 nike

你好,我可以在 mysql 工作台中使用 tcp/ip 通过 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 是数据库名称root & root是密码 mysql的用户名和密码3306默认端口

最佳答案

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

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

如果您使用 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>

关于java - mysql jdbc与ssl连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40761353/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com