In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article is about how Java accesses SSL enabled DB2 Database. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Generate the JAVA JKS certificate file and prepare it for JDBC. The password here is the password used to encrypt the file. You can set it at will, and set it to hell0man here.
You don't have to generate a certificate file on DB2 Server, anywhere you can run Java.
The mydbserver.arm here is taken from DB2 Server.
$keytool-import-trustcacerts-file "mydbserver.arm"-keystore "mynewdbclient.jks" Sample Java code
=
Public class SSLTest
{
Public static void main (String [] args)
{
String ServerName = "192.168.110.10"
Int PortNumber = 50001
String DatabaseName = "TEST"
Java.util.Properties properties = new java.util.Properties ()
Properties.put ("user", "db2inst1");-- > user name for accessing the database
Properties.put ("password", "passw0rd");-- > password to access the database
Properties.put ("sslConnection", "true")
System.setProperty ("javax.net.ssl.trustStore", "C:\ temp\\ ssl_client\\ mynewdbclient.jks")
System.setProperty ("javax.net.ssl.trustStorePassword", "hell0man")
String url = "jdbc:db2://" + ServerName + ":" + PortNumber + "/" + DatabaseName+ ": traceFile=foobar.txt;traceLevel=" + 0xFFFFFFFFFF + ";"
Java.sql.Connection con = null
Try
{
Class.forName (com.ibm.db2.jcc.DB2Driver) .newInstance ()
}
Catch (Exception e)
{
System.out.println ("Error: failed to load Db2 jcc driver.")
}
Try
{
System.out.println ("url:" + url)
Con = java.sql.DriverManager.getConnection (url, properties)
Java.sql.Statement S2 = con.createStatement ()
Try
{
S2.executeUpdate ("drop table T1")
}
Catch (Exception e)
{
System.out.println ("drop is failing")
}
Try
{
S2.executeUpdate ("create table T1 (C1 int)")
}
Catch (Exception e)
{
System.out.println ("create is failing")
}
String str = "insert into T1 values (100)"
S2.executeUpdate (str)
Java.sql.PreparedStatement ps = con.prepareStatement ("select * from T1")
Java.sql.ResultSet rs = ps.executeQuery ()
While (rs.next ())
{
System.out.println (rs.getString (1))
}
Con.close ()
}
Catch (Exception e)
{
E.printStackTrace ()
}
}
}
Thank you for reading! This is the end of the article on "how Java accesses SSL enabled DB2 Database". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.