Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- No suitable driver found for jdbc mysql?
- import java.sql.*;
- public class FirstExample {
- //static final String S_JDBC_DRIVER = "com.mysql.jdbc.Driver";
- static final String S_DB_URL = "jdbc:mysql://localhost:3306/emp";
- static final String S_USER = "root";
- static final String S_PASS = "root";
- public static void main(String[] args) {
- try {
- System.out.println("Connecting to database...");
- //Class.forName(S_JDBC_DRIVER);
- Connection connection = DriverManager.getConnection(S_DB_URL,
- S_USER, S_PASS);
- System.out.println("Creating statement...");
- Statement statement = connection.createStatement();
- String sql = "SELECT * FROM Employee";
- ResultSet resultSet = statement.executeQuery(sql);
- while (resultSet.next()) {
- int iId = resultSet.getInt("id");
- int iAge = resultSet.getInt("age");
- String sFirst = resultSet.getString("fname");
- String sLast = resultSet.getString("lname");
- System.out.print("ID: " + iId);
- System.out.print("tAge: " + iAge);
- System.out.print("tFirst: " + sFirst);
- System.out.println("tLast: " + sLast);
- }
- resultSet.close();
- statement.close();
- connection.close();
- } catch (SQLException se) {
- for (Throwable t : se) {
- t.printStackTrace();
- }
- }
- System.out.println("Goodbye!");
- }
- Connecting to database...
- java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/emp
- at java.sql.DriverManager.getConnection(Unknown Source)
- at java.sql.DriverManager.getConnection(Unknown Source)
- at FirstExample.main(FirstExample.java:21)
- Goodbye!
Add Comment
Please, Sign In to add comment