1
package SeleWeb;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.sql.*;


 public class seldata 

 {

   public static void main(String[] args) throws Exception 

    {

   Connection connection;
   Statement statement;
   ResultSet rs;

   WebDriver driver = new FirefoxDriver();
   String dbaseURL = "http://localhost:3306/selenium";
   driver.get(dbaseURL);
   String user = "root";
   String password = "";
   connection = null;
   try {    
           Class.forName("com.mysql.jdbc.Driver");
           System.out.println("Connecting to Database...");
           connection = DriverManager.getConnection(dbaseURL, user, password);

           //connection = DriverManager.getConnection("dbaseURL","root","");
           System.out.println("AAAAAAAAAAAAAAAAAAAAAAA");
           if (connection != null) 
            {
                System.out.println("Connected to the Database...");
                try {
                        String query = "select * from employee";
                        statement = connection.createStatement();
                        rs = statement.executeQuery(query);

                        while(rs.next()){
                            int EmpId= rs.getInt("EmpId");
                            String EmpName= rs.getString("EmpName");
                            String EmpAddress=rs.getString(3);
                            String EmpDept=rs.getString("EmpDept");
                            Double EmpSal= rs.getDouble(5);
                            System.out.println(EmpId+"\t"+EmpName+"\t"+EmpAddress+"\t"+EmpSal+"\t"+EmpDept);
                      }
                    } catch (SQLException ex) 
                        {
                            ex.printStackTrace();
                        }
                }

            }catch (SQLException ex) 
            {
                ex.printStackTrace();
            }

               }


     }
7
  • Which JARs you have imported to project for database connection? Commented Dec 31, 2015 at 11:27
  • mysql-connector-java-5.0.8-bin.jar Commented Dec 31, 2015 at 11:28
  • Can you please use latest JAR from here : code.google.com/p/find-ur-pal/downloads/… Commented Dec 31, 2015 at 11:31
  • not worked, same error reproduces Commented Dec 31, 2015 at 11:33
  • You need to check if your jar matches with the mysql(variant) you are trying to connect with. Commented Dec 31, 2015 at 13:35

1 Answer 1

2

Usually this exception occurs when the JDBC URL is wrong and not accepted by loaded drivers. You should have the jar files in the classpath. Also Try using JDBC driver specific URI prefix, which is jdbc:mysql:// for MySQL. I mean defining

String dbaseURL = "jdbc:mysql://localhost:3306/selenium";

instead of

String dbaseURL = "http://localhost:3306/selenium";
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.