Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: I need help! SQL Exception!

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default I need help! SQL Exception!

    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!


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: I need help! SQL Exception!

    When posting java code use [code=java] before your code and [/code] after your code.
    A brief rundown over the forum rules might be useful also

  3. #3
    Member
    Join Date
    Jul 2012
    Posts
    71
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default Re: I need help! SQL Exception!

    for one thing you have a space between the C and the L in your setDefaultCloseOperation so that's probably the first exception.... since its sql im guessing you have a database of passwords or something that you trying to access but other than that this code looks pretty clean.... next time use "highlight=Java" at the beginning of your code and "/highlight" at the end for the reader's sake (of course exclude the quotation marks and put [ ] instead)
    Last edited by C++kingKnowledge; August 17th, 2012 at 10:53 AM.

  4. #4
    Junior Member
    Join Date
    Aug 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I need help! SQL Exception!

    I solved it, and the problem was Login l=new Login(), I deleted the statement and problem solved Thanks anyway

  5. #5
    Junior Member
    Join Date
    Aug 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: I need help! SQL Exception!

    Got it, thanks

Similar Threads

  1. Exception
    By prabhakar in forum Exceptions
    Replies: 5
    Last Post: July 21st, 2012, 06:51 AM
  2. Replies: 5
    Last Post: September 5th, 2011, 10:31 AM
  3. [SOLVED] Should I use an exception here?
    By whity in forum Java Theory & Questions
    Replies: 3
    Last Post: May 4th, 2011, 06:52 AM
  4. Replies: 6
    Last Post: March 25th, 2011, 03:42 PM
  5. can someone please help me im getting exception
    By kristynrod in forum Exceptions
    Replies: 2
    Last Post: March 15th, 2011, 04:40 PM