Jdbc-mysql base DatabaseMetaData View MySQL version number, main/minor version number

Source: Internet
Author: User
Tags getmessage mysql version stub throwable

Li Wu:
Learn to think more, honouring teachers save Thanksgiving. Leaf See Root 321, rivers with one.
Meekness Conscience Lord, willing to do without regrets to the most bitter. Reading exercise strong body and mind, Prudential advised and the line and cherish.

Data,
data, Lingen on the data. Cloud computing, AI and other technologies are based on data. You must be cautious about operating the database. Give the most bitter code here, and take a look at it, to have your own judgment. Meet the choice, or ashamed to ask.
Javase:8
mysql:5.7.14
mysql-connector-java:5.1.44
Os:windows7 x64
Ide:myeclipse

Special exception classes

Package com.jizuiku;/** * This class is important, that is, to complete the action of throwing exceptions, by compiling, but also to keep the interface of the data logic layer concise. *  * @author Blog Park-to the most bitter * @version V17.11.08 */public class Daoexception extends RuntimeException {/** *  */private STA Tic final Long serialversionuid = 1l;public daoexception () {//TODO auto-generated constructor stub}public daoexception (St Ring message) {super (message);//TODO auto-generated constructor stub}public daoexception (Throwable cause) {Super (cause );//TODO auto-generated constructor stub}public daoexception (String message, Throwable cause) {Super (message, cause);// TODO Auto-generated Constructor stub}public daoexception (String message, Throwable cause, Boolean enablesuppression, Boolean writablestacktrace) {super (message, cause, enablesuppression, writablestacktrace);//TODO auto-generated Constructor stub}}

Code for the Jdbcutils class

Package Com.jizuiku;import Java.sql.connection;import Java.sql.drivermanager;import java.sql.PreparedStatement; Import Java.sql.resultset;import java.sql.sqlexception;/** * * * @author to most bitter * @version V17.11.07 */public final class J dbcutils {/** * URL format, JDBC: Sub-Protocol: Sub-name//hostname: Port number/database name? property Name = Property Value & Property name = attribute value * There are multiple parameters in the configstring variable, which requires deep study of their specific meanings */ private static String configstring = "? useunicode=true&characterencoding=utf8&usessl=true";p rivate static String url = "Jdbc:mysql://localhost:3306/jdbcforjava" + configstring;//local MySQL database (No child name) port number 3306  Database jdbcforjavaprivate static String user = "root";p rivate static string password = "";//tool class, direct use, not raw object private jdbcutils () {}//registered driver, where the static code block is applied only once the feature static {try {Class.forName ("Com.mysql.jdbc.Driver");} catch ( ClassNotFoundException e) {//TODO auto-generated catch Blockthrow new Exceptionininitializererror (e);}} /** * Get a link to a specified database * */public static Connection getconnection () throws SQLException {return Drivermanager.getconnection (url, user, password);} /** * Frees three resources ResultSet preparedstatement Connection * */public static void Free (ResultSet rs, PreparedStatement PS, Connec tion con) {try {if (rs! = null) {Rs.close ()}} catch (SQLException e) {//TODO auto-generated catch Blockthrow new Daoexce Ption (E.getmessage (), E); Finally {try {if (PS! = null) {Ps.close ()}} catch (SQLException e) {//TODO auto-generated catch Blockthrow new daoexcept Ion (E.getmessage (), e);} Finally {try {if (con! = null) {Con.close ()}} catch (SQLException e) {//TODO auto-generated catch Blockthrow new Daoexce Ption (E.getmessage (), E);}}}}

Test class Code

Package Com.jizuiku;import Java.sql.connection;import Java.sql.databasemetadata;import java.sql.PreparedStatement; Import Java.sql.resultset;import java.sql.sqlexception;/** * Demo class *  * @author Blog Park-give the most bitter * @version V2017.11.13 */public C Lass Demo {public static void main (string[] args) {Connection conn = null; PreparedStatement PS = null; ResultSet rs = null;try {//GET link conn = jdbcutils.getconnection ();D atabasemetadata Dbmd = Conn.getmetadata (); SYSTEM.OUT.PRINTLN ("Database name:" + dbmd.getdatabaseproductname ()); SYSTEM.OUT.PRINTLN ("Database version number:" + dbmd.getdatabaseproductversion ()); System.out.println ("Major version number of database:" + dbmd.getdatabasemajorversion ()); System.out.println ("Release version number of the database:" + dbmd.getdatabaseminorversion ());} catch (SQLException e) {//TODO auto-generated catch Blockthrow new Daoexception (E.getmessage (), e);} Release Resources Jdbcutils.free (RS, PS, conn);}}

Results show

Knowledge expansion

"MySQL version number description and view method", Post link is: http://blog.csdn.net/kk185800961/article/details/50667328

Learning resources: Itcast and Itheima Video library. If you have public resources, can share to me, with your resources to learn also can.
Blog post is to watch the video, into thinking written. It's good that the teacher speaks well. Blog bad, is to give the most bitter not serious.

Jdbc-mysql base DatabaseMetaData View MySQL version number, main/minor version number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.