Click here to Skip to main content
16,021,911 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am trying to connect login page and sql database but it throws an exception that "com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception.
**BEGIN NESTED EXCEPTION**
java.net.ConnectException
MESSAGE: Connection refused:connect
STACKTRACE
..........."

Code:
String sql = "select * from login where username=? and password = ?";
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://MANOSHRI/testsql", "manoshri", "wamanbaba");
pst = con.prepareStatement(sql);
pst.setString(1, user.getText());
pst.setString(2, pass.getText());
rs = pst.executeQuery();
if(rs.next())
{
JOptionPane.showMessageDialog(null, "Username and password matched..");
}
else
{
JOptionPane.showMessageDialog(null, "Not matched");
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null, ex);
}

What I have tried:

I am just a beginner so i didn't try anything...
Plzz help me in a simple way...
Posted
Updated 19-May-19 6:21am
Comments
[no name] 19-May-19 7:17am    
You need to look into why the connection is being refused. Look at the rest of the stacktrace, and also the logs on the server.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900