import java.sql.*;
public class GetAllRows{
public static void main(String[] args) {
System.out.println("Getting All Rows from a table");
Connection con = null;
String url = "jdbc:mysql://localhost:80/";
String db = "Flights";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "pass";
try{
//Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db, user, pass);
try{
Statement st = con.createStatement();
ResultSet res = st.executeQuery("SELECT * FROM flight");
//System.out.println(" " + "\t" + " ");
while (res.next()) {
int i = res.getInt("Flno");
String s = res.getString("ffrom");
String a = res.getString("tto");
String b = res.getString("distance");
String c = res.getString("departs");
String d = res.getString("arrives");
System.out.println(i + "\t\t" + s + "\t\t" + a + "\t\t" + b + "\t\t" + c + "\t\t" + d);
}
con.close();
}
catch (SQLException s){
System.out.println("SQL code does not execute.");
}
}
catch (Exception e){
e.printStackTrace();
}
}
}
// **Output**
//Getting All Rows from a table
//java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:80/Flights
//at java.sql.DriverManager.getConnection(Unknown Source)
//at java.sql.DriverManager.getConnection(Unknown Source)
//at GetAllRows.main(GetAllRows.java:15)
alafift 0 Newbie Poster
Recommended Answers
Jump to PostAnd as for your exception, you need to add the jar file of your driver to the path.
Nope. Or, at least, not yet. That error means that Java can not find any loaded driver that matches the provided url, not that java can not load the class, but rather, …
All 2 Replies
DJSAN10 28 Posting Whiz in Training
masijade 1,351 Industrious Poster Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.