官术网_书友最值得收藏!

Using the MySQL connector

Before testing the MySQL database connection from a Java program, one would need to add the MySQL JDBC connector library to the classpath. In this section, you will learn how to configure/add the MySQL JDBC connector library to the classpath while working with the Eclipse IDE or command console.

The MySQL connector (Connector/J) comes in a ZIP file, (*.tar.gz). The MySQL connector is a concrete implementation of the JDBC API. Once extracted, one can see a JAR file with a name such as mysql-connector-java-xxx.jar. The following are the different ways in which this JAR file is dealt with while working with or without IDEs such as Eclipse:

  • While working with the Eclipse IDE, one can add the JAR file to the class path by adding it as a library to the Build Path in the project's properties.
  • While working with the command console, one needs to specify the path to the JAR file in the -cp or -classpath argument when executing the Java application. The following is the sample command representing the preceding: 
        java -cp .;/path/to/mysql-connector-java-xxx.jar   
com.healthapp.JavaClassName

Note the "." in the classpath (-cp) option. This is there to add the current directory to the classpath as well such that  com.healthapp.JavaClassName can be located. 

主站蜘蛛池模板: 莱芜市| 罗源县| 包头市| 蒲城县| 阳曲县| 灌南县| 四平市| 弋阳县| 嘉善县| 建始县| 兴宁市| 桐柏县| 龙岩市| 北票市| 海口市| 名山县| 比如县| 松原市| 太原市| 息烽县| 日照市| 乌拉特前旗| 南康市| 绥芬河市| 鸡东县| 房产| 墨竹工卡县| 东阿县| 广南县| 田阳县| 自治县| 阿拉尔市| 双牌县| 安阳市| 芷江| 万州区| 华池县| 武汉市| 南皮县| 宜昌市| 新乐市|