-3

I am making a program for the interviewers to submit their marks for a particular candidate. The interviews are on 5.7.18 and I have to submit the program before Tuesday/Wednesday. I am unable to connect to the MySQL database. I think there is some problem in user creation. The marks entered from 5 different PCs should go to a MySQL database in a different PC

Here is my url/password/username -

private static final String URL = "jdbc:mysql://192.168.1.35:3306/interview";
    private static final String USER = "root";
    private static final String PASSWORD = "ubuntu";

Here is my JAVA code -

try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            Connection con = DriverManager.getConnection(URL, USER, PASSWORD);
            JOptionPane.showMessageDialog(null,"Connection Established!","Alert", JOptionPane.INFORMATION_MESSAGE);
            String q1="select username from users";
            Statement st = con.createStatement();
            String usr=jTextField2.getText();
            String psw=(new String(jPasswordField1.getPassword()));
            ResultSet rs = st.executeQuery(q1);
            boolean flag_usr=false;
            while(rs.next())
                {
                    if(usr.equals(rs.getString("username")))
                    {
                        flag_usr=true;
                    }
                }
            if(flag_usr==true)
            {
                String q2="select password from users";
                ResultSet rs1 = st.executeQuery(q2);
                boolean flag_psw=false;
                while(rs1.next())
                {
                    if(psw.equals(rs1.getString("password")))
                    {
                        this.dispose();
                    JOptionPane.showMessageDialog(null,"Login successful!","Alert", JOptionPane.INFORMATION_MESSAGE);
                    new Marks().setVisible(true);
                    }
                }
            }

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }

And I am getting this error on clicking login button in whose function the above code is written -

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at interview.portal.Login.jButton1ActionPerformed(Login.java:178)
    at interview.portal.Login.access$000(Login.java:21)
    at interview.portal.Login$1.actionPerformed(Login.java:81)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6533)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
    at java.awt.Component.processEvent(Component.java:6298)
    at java.awt.Container.processEvent(Container.java:2236)
    at java.awt.Component.dispatchEventImpl(Component.java:4889)
    at java.awt.Container.dispatchEventImpl(Container.java:2294)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
    at java.awt.Container.dispatchEventImpl(Container.java:2280)
    at java.awt.Window.dispatchEventImpl(Window.java:2746)
    at java.awt.Component.dispatchEvent(Component.java:4711)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
    at java.awt.EventQueue$4.run(EventQueue.java:731)
    at java.awt.EventQueue$4.run(EventQueue.java:729)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
BUILD SUCCESSFUL (total time: 5 seconds)
user207421
  • 305,947
  • 44
  • 307
  • 483
  • 1
    Whether 5.7.18 is May 7, 2018 or July 5, 2018, I'd say we're way beyond "urgent" at this late date =(:0). – Kevin Anderson Jul 29 '18 at 11:02
  • 1
    This information is not relevant to your question and will just generate down-votes: "I have to submit the program before Tuesday/Wednesday.", "URGENT". – Patrick Parker Jul 29 '18 at 11:06
  • 1
    Give me the name and contact info for your teacher and I will get you an extension. – nicomp Jul 29 '18 at 11:12

2 Answers2

1

It seems the mysql connectivity library is not included in the project. Solve the problem following one of the proposed solutions:

Refer

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse

Vaibhav Singh
  • 177
  • 10
0

Download a MySQL Connector/J and add the .jar to your classpath.

jurez
  • 4,436
  • 2
  • 12
  • 20