0

i have homework, and i need use mysql and java. i need acces to my table on mysql workbench, the table employeee, i download the driver and do every thing right, but i get error of :

The server time zone value '???? ???? ???????' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

if its relevant this is my code.

   import java.sql.*;

public class Driver {
public static void main(String[] args)  {
    Connection myConn = null;
    try {
        myConn =(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/employee", 
"root", "root");

        //create statement
        Statement myStmt = myConn.createStatement();
        if (myConn !=null) {
            System.out.println("connection succsesful");
            //excute sql query
            ResultSet myRs = myStmt.executeQuery("select * from project");

            //process the result set
            while(myRs.next()) {
                System.out.println(myRs.getString("DNUM") + "," + myRs.getString("PNUMBER"));
            }
        }
    }
    catch(Exception exc) {
        System.out.println("connection failed");
        exc.printStackTrace();
     }
   }
}
Sean Bright
  • 118,630
  • 17
  • 138
  • 146
yacov27
  • 29
  • 6

3 Answers3

1

Change the first argument to DriverManager.getConnection from "jdbc:mysql://localhost:3306/employee" to "jdbc:mysql://localhost:3306/employee?serverTimezone=UTC.

If you don't want to use UTC, substitute UTC for the timezone you want the database to record/display times in.

rpmartz
  • 3,759
  • 2
  • 26
  • 36
1

So in the end, I downloaded mysql-connector-java-5.1.48 driver and now its work well.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
yacov27
  • 29
  • 6
-1

Your next question - how i can check if he input Incorrect query on sql language? I think if your sql query syntax is wrong, you will receive MySQLSyntaxErrorException. And you can check ResultSet is empty.

ResultSet rs = stmt.executeQuery(yourQuery);
if(rs.next()==false)
 System.out.println("ResultSet is empty");
else{
 while(rs.next()){
  //get data from table
 }
}
Thida Swe Zin
  • 289
  • 1
  • 6
  • This is incorrect: it will skip the first row, you would need to use `do-while` instead. Also this doesn't answer the question that was asked. You also shouldn't use comparisons like `rs.next() == false`, use `!rs.next()` or invert the if statement. – Mark Rotteveel Jan 08 '20 at 10:24