import java.sql.*;
import java.io.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Login extends JFrame
{
String user;
String password;
String URL="jdbc:mysql://localhost:3306/abccs";
Connection con;
Container c=getContentPane();
JTextField jt=new JTextField();
JTextField j1=new JTextField();
JTextField j2=new JTextField(500);
JButton jb=new JButton("Login!");
public void LoadDriver() throws ClassNotFoundException
{
Class.forName("com.mysql.jdbc.Driver");
j2.setText("Driver Loaded!");
}
public Login()
{
setVisible(true);
setBounds(0,0,800,600);
setLayout(null);
setDefaultCloseOperation(WindowConstants.EXIT_ON_C LOSE);
c.add(jt);
c.add(j1);
c.add(j2);
c.add(jb);
jt.setBounds(300,150,200,50);
j1.setBounds(300,250,200,50);
j2.setBounds(300,350,200,180);
jb.setBounds(300,50,200,50);
jb.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0) {
Login l=new Login();
user=jt.getText();
password=j1.getText();
try {
l.LoadDriver();
l.getConnection();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
});
}
public Connection getConnection()
{
try{
con=DriverManager.getConnection(URL,user,password) ;
}catch(SQLException e)
{
if(e!=null)
j2.setText("Incorrect Password!");
else
j2.setText("Database Connected!");
e.printStackTrace();
}
return con;
}
public static void main(String[] args)
{
Login l=new Login();
}
}
Hey guys, I'm using MySQL, the username and password are both "root", but it keeps telling me this:
java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO)
at com.mysql.jdbc.SQLError.createSQLException(SQLErro r.java:946)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:2985)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.ja va:885)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java: 3421)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:12 47)
at com.mysql.jdbc.Connection.createNewIO(Connection.j ava:2775)
at com.mysql.jdbc.Connection.<init>(Connection.java:1 555)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonReg isteringDriver.java:285)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Login.getConnection(Login.java:57)
at Login$1.actionPerformed(Login.java:47)
at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Thanks for help guys!