我创建了一个.jar文件,里面有我签名的数字证书,我想在我的项目中使用该文件,如何在& JAVA_HOME / jre7 / lib / security文件夹中使用它。
先谢谢你的帮助:)。
答案 0 :(得分:0)
如果JAR在你的类路径上,并且文件是位于根目录的“foo.cert”,那就这样做......
InputStream is = this.getClass().getResourceAsStream("/foo.cert");
CertificateFactory factory = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate) factory.generateCertificate( is);
答案 1 :(得分:0)
static Connection DBConnectionstring()
{
Connection con = null;
String conUrl = "jdbc:sqlserver://localhost:1433; databaseName=paytest; user=My-PC; password=; integratedSecurity=true; encrypt=true; trustStore=truststore.jks;trustStorePassword=pass; hostNameInCertificate=certificatekey;";
try
{
con = DriverManager.getConnection(conUrl);
JOptionPane.showMessageDialog(null,"Connection is open!","Connection",JOptionPane.WARNING_MESSAGE);
}
catch (SQLException e)
{
e.printStackTrace();
}
return con;
}//connection string method ends
这是我有连接字符串和其他sql命令的类
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.net.ssl.*;
import java.io.*;
import java.net.*;
import java.security.*;
import javax.swing.JOptionPane;
public abstract class ConnectionDB
{
public static void main(String[] args)
{
try {
insertRecordIntoDbUserTable();
selectfromdb();
}
catch (SQLException e)
{
System.out.println(e.getMessage());
}
}
private static void GuiContain()
{
}
private static void insertRecordIntoDbUserTable() throws SQLException
{
Connection con = null;
Statement statement = null;
String insertTableSQL = "INSERT INTO LoginDetails" + "(Username, Password) " + "VALUES" + "('username','pass1')";
try
{
con = DBConnectionstring();
statement = con.createStatement();
System.out.println(insertTableSQL);
statement.executeUpdate(insertTableSQL);
//System.out.println("Record's inserted into Login Details table!");
JOptionPane.showMessageDialog(null,"Your Data has been Inserted","Data Inserted",JOptionPane.WARNING_MESSAGE);
}
catch (SQLException e)
{
System.out.println(e.getMessage());
}
finally
{
if (statement != null)
{
statement.close();
//System.out.println("XXXXX...Statement is terminated..XXXXX");
JOptionPane.showMessageDialog(null,"Statement is closed","Statement",JOptionPane.WARNING_MESSAGE);
}
if (con != null)
{
con.close();
//System.out.println("Connection is Closed!!..");
JOptionPane.showMessageDialog(null,"Connection is closed!","Connection",JOptionPane.WARNING_MESSAGE);
}
}
}
private static void selectfromdb() throws SQLException
{
Statement stmt = DBConnectionstring().createStatement();
ResultSet rs = stmt.executeQuery("SELECT Username,Password FROM LoginDetails");
while (rs.next())
{
String lastName = rs.getString("Username");
String Pass = rs.getString("Password");
System.out.println(lastName + "" + Pass + "\n");
}
}
static Connection DBConnectionstring()
{
Connection con = null;
String conUrl = "jdbc:sqlserver://localhost:1433; databaseName=paytest; user=my-PC; password=; integratedSecurity=true;";
try
{
con = DriverManager.getConnection(conUrl);
JOptionPane.showMessageDialog(null,"Connection is open!","Connection",JOptionPane.WARNING_MESSAGE);
}
catch (SQLException e)
{
e.printStackTrace();
}
return con;
}
}