Use JDBC/Mysql Connector in intellij idea

前端 未结 4 437
没有蜡笔的小新
没有蜡笔的小新 2020-12-29 09:17

I\'m new in Java, and I need to establish a connection to a MySQL server (local), I have add the libraries in Intellij idea but it seems not work, the IDE can\'t find the cl

相关标签:
4条回答
  • 2020-12-29 09:45

    It's easy to configure first just open the InteliJ IDE and follow this simple step

    File->Project Structure->Libraries
    

    Then Click on the plus(+) sign and select From Meven....

    After you'll get a search box there you should put

    mysql:mysql-connector-java:5.1.40

    This will solve the issue

    0 讨论(0)
  • 2020-12-29 09:45

    Solution#1:Drop the mysql-connector-java-version-bin.jar file to your project, right click on it, select "Add as library".

    Solution#2:Build and run with command line, for example(Windows)

    • javac yourclassname
    • java -cp".;mysql-connector-java-version-bin.jar" yourclassname
    0 讨论(0)
  • 2020-12-29 09:53

    You have to add 'mysql:mysql-connector-java:5.1.40' from maven or add it as java library as shown:

    0 讨论(0)
  • 2020-12-29 09:58

    If it says time zone unrecognized you can add this piece of code to the URL:

    Connection connection = DriverManager.getConnection("jdbc:mysql://localhost?useTimezone=true&serverTimezone=UTC","USER-NAME","PASSWORD");
    

    Don't forget to wrap it with a try-catch.

    0 讨论(0)
提交回复
热议问题