I am trying to figure out why I can't pull data from MySQL in Java. The codes are below for both Java and MySQL. I get no error from the catch statement in the java. Any help is much appreciated!!
Java: package com.mysql.java;
import java.sql.*;
public class DBConnect {
private Connection con;
private Statement st;
private ResultSet rs;
public DBConnect(){
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/demo", "root", "Guitars16");
st = con.createStatement();
}catch(Exception ex){
System.out.println("Could not load database!!" + ex);
}
}
public void getData(){
try{
String query = "select * from demo.football";
rs = st.executeQuery(query);
System.out.println("Records from Database");
while(rs.next()){
String name = rs.getString("First Name");
String last = rs.getString(2);
System.out.println("First Name: " + name + "Last Name: " + last);
}
}catch(Exception ex){
System.out.println("Could not load data!!");
}
}
public static void main(String[] args) {
DBConnect connect = new DBConnect();
}
}
Console: Sat Oct 08 22:17:11 EDT 2016 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
MySQL: SELECT * FROM demo.football;
Table: demo.Tables.football ValueOfPlayer, First Name, Last Name, Position
in the table I put 8, Sam, Bradford, QB