-1

我创建了一个 .jar 文件,其中包含我的签名数字证书,我想在我的项目中使用该文件,目前我如何使用它,它位于 &JAVA_HOME/jre7/lib/security 文件夹中。

提前感谢您的帮助:)。

4

2 回答 2

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;

    }


    }
于 2013-06-01T08:20:11.530 回答
0

如果 JAR 在您的类路径中,并且文件是位于根目录下的“foo.cert”,请执行此操作...

InputStream is = this.getClass().getResourceAsStream("/foo.cert");
CertificateFactory factory = CertificateFactory.getInstance("X.509");  
X509Certificate cert = (X509Certificate) factory.generateCertificate( is);  

https://stackoverflow.com/a/4548791/791406

于 2013-05-30T18:17:50.760 回答