I want to create my database using pure sql code from sql command line sql command line imageand want to connect to the database from java code(jdbc). But while doing so I am facing problems- here is what I have tried: I have set the path of the driver - ["mysql-connector-java-5.1.39-bin"-a jar file ]- in path variable as well as ,on some suggestions from internet, I added this jar file to the [C:\Program Files\Java\jdk1.8.0\jre\bin] folder. but when I run my program from command prompt it shows an Exception - the image - message from command prompt. I have created a user for the databse from sql command prompt too. here is my java code -
import java.sql.*;
public class JDBCDemo
{
public static void main(String... args)
{
try(Connection conn = DriverManager.getConnection(
"jdbc:mysql//localhost:3306/studentdb?useSSL=false","amir","amir5");
// step 2 . allocate a statement object in the connection
Statement stmt = conn.createStatement();
) {
//step 3. execute a SQL select query, the query result
String strSelect = "select * from student;";
System.out.println("The sql query is "+ strSelect);
System.out.println();
ResultSet rset = stmt.executeQuery(strSelect);
System.out.println("the records are selected");
int rowCount =0;
while(rset.next())
{
String name = rset.getString("name");
String roll = rset.getString("roll_num");
int id = rset.getInt("id");
System.out.println(name+", "+roll+", "+id);
++rowCount;
}
System.out.println(rowCount);
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
how can I get rid of this problem?