7 Replies - 252 Views - Last Post: 08 April 2019 - 06:00 PM Rate Topic: -----

#1 awthz   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 76
  • Joined: 13-February 17

No suitable driver found for jdbc:mysql:

Posted 05 April 2019 - 09:34 PM

Hi guys, Im trying to connect to my database and run with this error.

No suitable driver found for jdbc:mysql://localhost:3306/assignment1

Am I missing something guys?

Thanks

package task2;

import java.sql.*;
import java.util.Scanner;


public class studentDB {
	
	static final String dbUrl  = "jdbc:mysql://localhost:3306/assignment1";
	static final String uname = "root";
	static final String password = "";
	
	private static Connection myCon = null;
	private static Statement stmt = null;
	private static PreparedStatement prepStmt = null;
	private static ResultSet res = null;
	
	static Scanner input = new Scanner (System.in);
	
	public static void studDB(String [] args) {
		System.out.println(" Check Attendance of the Class \n " + "[y] - Yes \t [n] - No ");
				System.out.println("Enter option");
				String choice = input.next();
				
				switch (choice) {
			
					
				case "y":
				case "Y":
					readDb(); break;
					
				case "n":
				case "N":
					insertDb(); break;
					

					default:
						System.out.println(" INVALID ENTRY");
					
				}
		
				
		
		
	}

	private static void insertDb() {
		// TODO Auto-generated method stub
		
	}

	private static void readDb() {
		// TODO Auto-generated method stub
		try {
			myCon = DriverManager.getConnection(dbUrl, uname, password);
			System.out.println("DB CONNECTION SUCCESFUL");
			stmt = myCon.createStatement();
			String sql = "select *from studentTab";
			res = stmt.executeQuery(sql);
			System.out.println("DB READING");
			System.out.println("=========");
			
			while (res.next()) {
				System.out.println(res.getString("lname" ) + ( ", " ) +  res.getString("fname" ) + ( "     " ) + ( "\t " )+ res.getString("lrn"));
			}
			stmt.close();
			myCon.close();
			
		} catch (SQLException e) {
			e.printStackTrace();
		} 
		
	}
	

}



Is This A Good Question/Topic? 0
  • +

Replies To: No suitable driver found for jdbc:mysql:

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6795
  • View blog
  • Posts: 28,082
  • Joined: 12-December 12

Re: No suitable driver found for jdbc:mysql:

Posted 06 April 2019 - 12:40 AM

Is that the exact, full, error message?

What steps did you take to make MySql available?
Was This Post Helpful? 0
  • +
  • -

#3 awthz   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 76
  • Joined: 13-February 17

Re: No suitable driver found for jdbc:mysql:

Posted 06 April 2019 - 03:18 AM

View Postandrewsw, on 06 April 2019 - 12:40 AM, said:

Is that the exact, full, error message?

What steps did you take to make MySql available?



java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/assignment1
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
at task2.studentDB.readDb(studentDB.java:55)
at task2.studentDB.studDB(studentDB.java:30)
at task2.gui$btnAct.actionPerformed(gui.java:75)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:279)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6632)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3342)
at java.desktop/java.awt.Component.processEvent(Component.java:6397)
at java.desktop/java.awt.Container.processEvent(Container.java:2263)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:5008)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2321)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4840)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4918)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4547)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4488)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2307)
at java.desktop/java.awt.window.dispatchEventImpl(window.java:2772)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4840)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:772)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:95)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:743)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:742)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)


This is the whole error.
I already install mySql workbench the n the wamp and copy the msql connector.jar in the project.
Was This Post Helpful? 0
  • +
  • -

#4 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3631
  • View blog
  • Posts: 16,675
  • Joined: 20-September 08

Re: No suitable driver found for jdbc:mysql:

Posted 06 April 2019 - 03:32 AM

Quote

I already install mySql workbench the n the wamp and copy the msql connector.jar in the project.


Please do this and post the output:

public static void studDB(String [] args) {
   System.out.println(System.getProperty("java.class.path"));   
   System.out.println(" Check Attendance of the Class \n " + "[y] - Yes \t [n] - No ");
   ...

Was This Post Helpful? 0
  • +
  • -

#5 awthz   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 76
  • Joined: 13-February 17

Re: No suitable driver found for jdbc:mysql:

Posted 08 April 2019 - 12:30 AM

This is the output sir.

A:\Java\Programms\IT7374_Assignment1_2184293\bin
Check Attendance of the Class
[y] - Yes [n] - No
Enter option
y

This post has been edited by andrewsw: 08 April 2019 - 12:42 AM
Reason for edit:: removed previous quote, just use the Reply button

Was This Post Helpful? 0
  • +
  • -

#6 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6795
  • View blog
  • Posts: 28,082
  • Joined: 12-December 12

Re: No suitable driver found for jdbc:mysql:

Posted 08 April 2019 - 12:42 AM

Note that there is no need to quote the previous post in full, there is a Reply button further down the page, or use the Fast Reply box.
Was This Post Helpful? 0
  • +
  • -

#7 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3631
  • View blog
  • Posts: 16,675
  • Joined: 20-September 08

Re: No suitable driver found for jdbc:mysql:

Posted 08 April 2019 - 02:36 AM

Quote

A:\Java\Programms\IT7374_Assignment1_2184293\bin


So, as you can see, there's no driver jar in your classpath (which is what the above is)
Was This Post Helpful? 1
  • +
  • -

#8 awthz   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 76
  • Joined: 13-February 17

Re: No suitable driver found for jdbc:mysql:

Posted 08 April 2019 - 06:00 PM

That make sense gOOse.

Thanks..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1