{"id":3414,"date":"2015-05-14T20:48:11","date_gmt":"2015-05-15T04:48:11","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=3414"},"modified":"2024-01-10T00:19:56","modified_gmt":"2024-01-10T07:19:56","slug":"jdbc-overview","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/jdbc-overview\/","title":{"rendered":"Introducing to JDBC"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn about JDBC and its main components that you can use to interact with MySQL databases.<\/p>\n\n\n\n<p>JDBC API provides a standard interface for interacting with any relational database management system (RDBMS). <\/p>\n\n\n\n<p>JDBC API consists of the following main components:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>JDBC Driver<\/li>\n\n\n\n<li>Connection<\/li>\n\n\n\n<li>Statement<\/li>\n\n\n\n<li>ResultSet<\/li>\n<\/ul>\n\n\n\n<p>Let\u2019s take a look at each component in more detail.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">JDBC Driver<\/h3>\n\n\n\n<p>A JDBC driver is a set of Java classes that implement JDBC interfaces for interacting with a specific database. <\/p>\n\n\n\n<p>Almost all database vendors such as MySQL, Oracle, and Microsoft SQL Server, provide JDBC drivers. For example, MySQL provides a JDBC driver called MySQL Connector\/J, allowing you to work with MySQL databases through a standard JDBC API.<\/p>\n\n\n\n<p>There are three types of JDBC drivers: <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>JDBC-native API Driver <\/li>\n\n\n\n<li>JDBC-net Driver<\/li>\n\n\n\n<li>JDBC Driver.<\/li>\n<\/ul>\n\n\n\n<p class=\"tip\">In this tutorial, we&#8217;ll discuss the JDBC driver, for more detailed information on the other driver types, you can check out the <a href=\"http:\/\/en.wikipedia.org\/wiki\/JDBC_driver\" target=\"_blank\" rel=\"noopener noreferrer\">JDBC driver<\/a>.<\/p>\n\n\n\n<p>JDBC Driver is written in pure Java. It translates JDBC calls into MySQL-specific calls and sends the calls directly to a specific database. <\/p>\n\n\n\n<p>To use a JDBC driver, include the driver JAR file with your application. MySQL Connector\/J is the JDBC driver.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Connection<\/h3>\n\n\n\n<p>The first and most important component of JDBC is the <code>Connection<\/code> object. <\/p>\n\n\n\n<p>In a Java application, you first load a JDBC driver and then <a href=\"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/connecting-to-mysql-using-jdbc-driver\/\">establish a connection to the database<\/a>. <\/p>\n\n\n\n<p>Through the <code>Connection<\/code> object, you can interact with the database such as creating a <code>Statement<\/code> to execute SQL queries against tables. You can open more than one connection to a database at the same time.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Statement<\/h3>\n\n\n\n<p>To execute an SQL query such as <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-select-from\/\">SELECT<\/a>, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-insert\/\">INSERT<\/a>, <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-update\/\">UPDATE<\/a>, and <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-delete\/\">DELETE<\/a> you can use a <code>Statement<\/code> object. You create the <code>Statement<\/code> object through the <code>Connection<\/code> object. <\/p>\n\n\n\n<p>JDBC provides several types of statements for different purposes such as <code>PreparedStatement<\/code> and <code>CallableStatement<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">ResultSet<\/h3>\n\n\n\n<p>After <a href=\"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/querying-data-from-mysql-using-jdbc\/\">querying data from the database<\/a>, you get a <code>ResultSet<\/code> object. The <code>ResultSet<\/code> object provides a set of APIs that allows you to traverse the query results.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Put it all together<\/h2>\n\n\n\n<p>The typical flow of using JDBC is as follows:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>First, load the JDBC driver and create a connection to the database.<\/li>\n\n\n\n<li>Then, create a <code>Statement<\/code> and <a href=\"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/querying-data-from-mysql-using-jdbc\/\">execute the query to get a ResultSet<\/a>.<\/li>\n\n\n\n<li>Next, traverse and process the <code>ResultSet<\/code> .<\/li>\n\n\n\n<li>Close the <code>ResultSet<\/code> , <code>Statement<\/code> , and <code>Connection<\/code> .<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"593\" height=\"83\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/05\/MySQL-JDBC-process-flow.jpg\" alt=\"MySQL JDBC process flow\" class=\"wp-image-3422\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/05\/MySQL-JDBC-process-flow.jpg 593w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/05\/MySQL-JDBC-process-flow-300x42.jpg 300w\" sizes=\"auto, (max-width: 593px) 100vw, 593px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>JDBC offers universal database access from Java.<\/li>\n\n\n\n<li>Use MySQL connector\/J as the driver to connect to MySQL from Java.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful? <\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"3414\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/jdbc-overview\/\"\n\t\t\t\tdata-post-title=\"Introducing to JDBC\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"3414\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/jdbc-overview\/\"\n\t\t\t\tdata-post-title=\"Introducing to JDBC\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn about JDBC and its main components that you can use to interact with MySQL databases.<\/p>\n","protected":false},"author":2,"featured_media":3669,"parent":3416,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-3414","page","type-page","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>JDBC Overview<\/title>\n<meta name=\"description\" content=\"In this tutorial, you will learn about JDBC and its main components that you can use to interact with MySQL databases.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/jdbc-overview\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JDBC Overview\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you will learn about JDBC and its main components that you can use to interact with MySQL databases.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/jdbc-overview\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-10T07:19:56+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/05\/mysql-jdbc-tutorial.png\" \/>\n\t<meta property=\"og:image:width\" content=\"120\" \/>\n\t<meta property=\"og:image:height\" content=\"100\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/jdbc-overview\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/jdbc-overview\\\/\",\"name\":\"JDBC Overview\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/jdbc-overview\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/jdbc-overview\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2015\\\/05\\\/mysql-jdbc-tutorial.png\",\"datePublished\":\"2015-05-15T04:48:11+00:00\",\"dateModified\":\"2024-01-10T07:19:56+00:00\",\"description\":\"In this tutorial, you will learn about JDBC and its main components that you can use to interact with MySQL databases.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/jdbc-overview\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/jdbc-overview\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/jdbc-overview\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2015\\\/05\\\/mysql-jdbc-tutorial.png\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2015\\\/05\\\/mysql-jdbc-tutorial.png\",\"width\":120,\"height\":100,\"caption\":\"MySQL JDBC Tutorial\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/jdbc-overview\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MySQL JDBC\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/mysql-jdbc-tutorial\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Introducing to JDBC\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\",\"name\":\"MySQL Tutorial\",\"description\":\"A comprehensive MySQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mysqltutorial.org\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JDBC Overview","description":"In this tutorial, you will learn about JDBC and its main components that you can use to interact with MySQL databases.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/jdbc-overview\/","og_locale":"en_US","og_type":"article","og_title":"JDBC Overview","og_description":"In this tutorial, you will learn about JDBC and its main components that you can use to interact with MySQL databases.","og_url":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/jdbc-overview\/","og_site_name":"MySQL Tutorial","article_modified_time":"2024-01-10T07:19:56+00:00","og_image":[{"width":120,"height":100,"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/05\/mysql-jdbc-tutorial.png","type":"image\/png"}],"twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/jdbc-overview\/","url":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/jdbc-overview\/","name":"JDBC Overview","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/jdbc-overview\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/jdbc-overview\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/05\/mysql-jdbc-tutorial.png","datePublished":"2015-05-15T04:48:11+00:00","dateModified":"2024-01-10T07:19:56+00:00","description":"In this tutorial, you will learn about JDBC and its main components that you can use to interact with MySQL databases.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/jdbc-overview\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/jdbc-overview\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/jdbc-overview\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/05\/mysql-jdbc-tutorial.png","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2015\/05\/mysql-jdbc-tutorial.png","width":120,"height":100,"caption":"MySQL JDBC Tutorial"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/jdbc-overview\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"MySQL JDBC","item":"https:\/\/www.mysqltutorial.org\/mysql-jdbc-tutorial\/"},{"@type":"ListItem","position":3,"name":"Introducing to JDBC"}]},{"@type":"WebSite","@id":"https:\/\/www.mysqltutorial.org\/#website","url":"https:\/\/www.mysqltutorial.org\/","name":"MySQL Tutorial","description":"A comprehensive MySQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mysqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3414","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/comments?post=3414"}],"version-history":[{"count":5,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3414\/revisions"}],"predecessor-version":[{"id":14455,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3414\/revisions\/14455"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3416"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media\/3669"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=3414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}