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.

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

yourClassName objectName = new yourClassName();

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();

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

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

check this

Now what after creating SSL certificate?

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)

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

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

ok jalpesh_007 I will do that ,thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.