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();
}
}
}
-
Which JARs you have imported to project for database connection?– Helping HandsDec 31, 2015 at 11:27
-
mysql-connector-java-5.0.8-bin.jar– PRasdDec 31, 2015 at 11:28
-
Can you please use latest JAR from here : code.google.com/p/find-ur-pal/downloads/…– Helping HandsDec 31, 2015 at 11:31
-
not worked, same error reproduces– PRasdDec 31, 2015 at 11:33
-
You need to check if your jar matches with the mysql(variant) you are trying to connect with.– TestingWithArifDec 31, 2015 at 13:35
1 Answer
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";