0

I have Class called ConnectionDB and in this class I have Main method and another function in the class ConnectionDB,That is

private static Connection DBConnectionstring()

In this function I have Connection URL ,Drivers inside this function .

I want this function to be used in another class (GUILogin) with main function in it and Login button on it.
I want ActionListner of the Login button to get that class from ConnectionDB.
I click on the button I want to get connected to the Database.

5
Contributors
10
Replies
64
Views
4 Years
Discussion Span
Last Post by chdboy
Featured Replies
  • 2

    also, get your terminology straight: Java doesn't have functions, it has methods. if I'm not mistaken, Connection is not a class, it's an interface. (I assume your ConnectionDB implements Connection?) `private static Connection myConnection = new ConnectionDB();` Read More

  • 2

    check [this](https://www.google.be/search?q=The+driver+could+not+establish+a+secure+connection+to+SQL+Server+by+using+Secure+Sockets+Layer+(SSL)+encryption.+Error%3A&rlz=1C1ASUT_enBE460BE475&aq=f&oq=The+driver+could+not+establish+a+secure+connection+to+SQL+Server+by+using+Secure+Sockets+Layer+(SSL)+encryption.+Error%3A&aqs=chrome.0.57.1026j0&sourceid=chrome&ie=UTF-8) Read More

  • No one is going to do your work for you, bro. :| Read More

0

I believe you need to create an object of the class you want to use in main.
More detail here.

yourClassName objectName = new yourClassName();
2

also, get your terminology straight: Java doesn't have functions, it has methods.

if I'm not mistaken, Connection is not a class, it's an interface. (I assume your ConnectionDB implements Connection?)

private static Connection myConnection = new ConnectionDB();

0

hai chdboy,

as above experts said

you may also try like this

import java.sql.DriverManager;
import java.sql.Connection;

public class connectionDB 
{
    public static Connection getCon()throws Exception 
    {
       Class.forName("your_database_driver_name_goes_here");
       Connection con = DriverManager.getConnection("your_connection_string_here","user_name_here","password_here");
       return con;
    }
}

call the getCon() method wherever you want by using its class name directly as follows

Conncetion con = connectionDB.getCon()

let me know the status

any comments are much appreciated

0
The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption. Error: "RSA premaster secret error". ClientConnectionId:9ffcc3af-96ed-4f55-b7f4-a49b958a8ac4

I get this error

0

Now what after creating SSL certificate?

Edited by chdboy

0
Caused by: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
    at java.security.cert.PKIXParameters.setTrustAnchors(Unknown Source)
    at java.security.cert.PKIXParameters.<init>(Unknown Source)
    at java.security.cert.PKIXBuilderParameters.<init>(Unknown Source)
0

you just have passed pass wrong parameters in certificate... so just check it out and run your project again.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.