I have created A .jar file which has my signed digital certificate inside it and I want to use that file in my project,how can I use it currently it's in &JAVA_HOME/jre7/lib/security folder.
Thanks for your help in advance :) .
I have created A .jar file which has my signed digital certificate inside it and I want to use that file in my project,how can I use it currently it's in &JAVA_HOME/jre7/lib/security folder.
Thanks for your help in advance :) .
If the JAR is on your classpath, and the file is "foo.cert" sitting at the root, just do this...
InputStream is = this.getClass().getResourceAsStream("/foo.cert");
CertificateFactory factory = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate) factory.generateCertificate( is);
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
And here is the class where I'm having connection string and other sql commands
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;
}
}