<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/">
    <channel>
        <title>CUBRID JDBC Tutorial - Part 1</title>
        <link>http://www.cubrid.org/?mid=accessing_cubrid_with_jdbc_part1</link>
        <description>CUBRID JDBC Tutorial - Part 1</description>
        <language>en</language>
        <pubDate>Mon, 11 Feb 2013 04:21:06 -0800</pubDate>
        <lastBuildDate>Mon, 11 Feb 2013 06:24:24 -0800</lastBuildDate>
        <generator>XpressEngine 1.4.4.1</generator>
                        										        <item>
            <title>CUBRID JDBC Tutorial - Part 1</title>
            <dc:creator>CUBRID</dc:creator>
            <link>http://www.cubrid.org/accessing_cubrid_with_jdbc_part1</link>
            <guid isPermaLink="true">http://www.cubrid.org/accessing_cubrid_with_jdbc_part1</guid>
                                    <description><![CDATA[<p></p>

<p class="MsoNormal"><b><span style="font-size:24.0pt;line-height:107%;color:#44546A">Accessing CUBRID with
JDBC&nbsp; - Part I<o:p></o:p></span></b></p>

<p class="MsoNormal"><span style="color:#44546A">February 2013<o:p></o:p></span></p>

<p class="MsoNoSpacing"><br /></p>

<p class="MsoNoSpacing">It’s been a while since we published our first JDBC <a href="/cubrid_jdbc_tutorial">tutorial</a>, in a time when
CUBRID was still using with the GLO data type… The time has come to take
another look at the CUBRID JDBC driver!</p>

<p class="MsoNoSpacing">We will be looking together in the first part of the
tutorial at the driver basics, and the second part will be dedicated to
specific CUBRID features.</p>

<p class="MsoNoSpacing">Before we start, these are the software prerequisites you
should have installed:</p>

<p class="MsoNoSpacing" style="margin-left:.5in;text-indent:-.25in;mso-list:l0 level1 lfo1">
</p>

<ul>
<li>CUBRID 9.0 (<a href="/?mid=downloads&amp;item=cubrid&amp;os=detect&amp;cubrid=9.0.0">here</a>)</li>
<li>Java SDK/JRE (you can find <a href="/wiki_apis/entry/setting-java-environment-path">here</a> the installation instructions)</li>
<li>Recommended <b>–IntelliJ IDEA Community edition</b> – you can find it <a href="http://www.jetbrains.com/idea/">here</a>. For those of you who don’t know yet, this is one of the best cross platform Java IDE available for free. Of course, you can also use any other IDE you prefer – Eclipse, NetBeans etc.</li>
</ul>
<p></p>

<table class="MsoNormalTable" border="1" cellspacing="0" cellpadding="0" style="border: none;">
 <tbody><tr>
  <td width="623" valign="top" style="width:467.5pt;border:solid windowtext 1.0pt;
  mso-border-alt:solid windowtext .5pt;background:#FBE4D5;padding:0in 5.4pt 0in 5.4pt">
  <p class="MsoNoSpacing">As for the driver installation, the key thing to
  remember is that the driver itself is part of the CUBRID engine installation!</p>
  <p class="MsoNoSpacing"><b>This means that
  once you have installed CUBRID, the driver is already installed on your
  system.<o:p></o:p></b></p>
  <p class="MsoNoSpacing">You will find in in the CUBRID installation folder, in
  the <b>&#92;jdbc</b> subfolder – <b>cubrid_jdbc.jar</b>.</p>

</tr></tbody></table><p><br /></p>

<p>

</p>

<p class="MsoNoSpacing"><span style="font-size:20.0pt">General notes about the
CUBRID JDBC driver<o:p></o:p></span></p>

<p class="MsoNoSpacing"><br /></p>

<p class="MsoNoSpacing">The Java Database Connectivity API - <a href="http://en.wikipedia.org/wiki/Java_Database_Connectivity"><b>JDBC</b></a> - is the industry Java
standard for database-independent connectivity between Java and SQL databases.
Each major RDBMS implements JDBC support and CUBRID is no exception. Actually,
both main CUBRID managers – <a href="/?mid=downloads&amp;item=cubrid_manager&amp;os=detect">CUBRID
Manager Client</a> and <a href="/?mid=downloads&amp;item=cubrid_query_browser&amp;os=detect&amp;cubrid=8.4.3">CUBRID
Query Browser</a> – are developed in Java, using the CUBRID JDBC driver! …and
it is not the only example – see also the <a href="/?mid=downloads&amp;item=cubrid_migration_toolkit&amp;os=detect&amp;cubrid=8.4.3">CUBRID
Migration Toolkit</a>.</p>

<p class="MsoNoSpacing">You can read more about JDBC here:</p>

<p class="MsoNoSpacing"><a href="http://www.dmoz.org/Computers/Programming/Languages/Java/Databases_and_Persistence/JDBC/">http://www.dmoz.org/Computers/Programming/Languages/Java/Databases_and_Persistence/JDBC/</a></p>

<p class="MsoNoSpacing">If you are already familiar with the JDBC standard, you
know that, the same as for ODBC, there are different levels of standards
compliance:</p>

<p class="MsoNoSpacing"><a href="http://oracle.su/docs/11g/java.112/e10589/jdbcvers.htm">http://oracle.su/docs/11g/java.112/e10589/jdbcvers.htm</a>.
Currently, the CUBRID JDBC driver is compliant with the <a href="http://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;cad=rja&amp;ved=0CD8QFjAB&amp;url=http%3A%2F%2Fwww.karunya.edu%2Fcse%2Fcollaboration%2Fsun%2Fresources%2Fjdbc20.stdext.pdf&amp;ei=xaoMUfaJDovcsgax_IHIDA&amp;usg=AFQjCNEmBldkm653Pn8PfTw1i5dAK7BL0g&amp;bvm=bv.41867550,d.Yms">JDBC
2.0 standard</a> – see <a href="/wiki_apis/entry/cubrid-jdbc-compatibility">http://www.cubrid.org/wiki_apis/entry/cubrid-jdbc-compatibility</a><span class="MsoHyperlink"><span style="font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;">.</span></span>
As a side note, there is some JDBC API 3.0 functionality implemented as well.</p>

<p class="MsoNoSpacing"><o:p>&nbsp;</o:p></p>

<p class="MsoNoSpacing">On top of the standard JDBC functionality, the driver
implements a set of extensions specific to CUBRID – see more in the next
sections of the tutorial.</p>

<table class="MsoNormalTable" border="1" cellspacing="0" cellpadding="0" style="border: none;">
 <tbody><tr>
  <td width="623" valign="top" style="width:467.5pt;border:solid windowtext 1.0pt;
  mso-border-alt:solid windowtext .5pt;background:#FBE4D5;padding:0in 5.4pt 0in 5.4pt">
  <p class="MsoNoSpacing"><b>Tip</b>: You can
  find the full JDBC driver API documentation online:</p>
  <p class="MsoNoSpacing"><a href="/manual/840/en/JDBC%20API">http://www.cubrid.org/manual/840/en/JDBC%20API</a></p>

</tr></tbody></table>

<p class="MsoNoSpacing"><span style="font-size:20.0pt"><br /></span></p>

<p class="MsoNoSpacing"><span style="font-size:20.0pt">A first JDBC program<o:p></o:p></span></p>

<p class="MsoNoSpacing"><br /></p>

<p class="MsoNoSpacing">The first small program we will develop using the CUBRID
JDBC driver will only do the followings basic operations:</p>

<ul>
<li>Connect to the <a href="/wiki_tutorials/entry/getting-started-with-demodb-cubrid-demo-database"><b>demodb</b></a> database</li>
<li>Query the JDBC driver version used</li>
<li>Disconnect</li>
</ul>

<p class="MsoNoSpacing">But before we start, let’s create an IntelliJ Java
project and add the CUBRID JDBC driver library to the project.</p>

<p class="MsoNoSpacing">To add the CUBRID JDBC driver to the project go to<b><i> File
-&gt; Project Structure</i></b>, and select the <b><i>Libraries </i></b>tab. Then,
click on the “+” button and select Java. Navigate to your CUBRID installation
path (default is C:&#92;CUBRID), and you will find <b><i>cubrid_jdbc.jar </i></b>in the <b><i>&#92;jdbc</i></b>
folder. Click OK and you are done.</p>

<p class="MsoNoSpacing" style="text-align: center; "><o:p><img src="http://www.cubrid.org/files/attach/images/236657/487/581/Libraries.png" alt="Libraries.png" width="659" height="357" editor_component="image_link"/>
&nbsp;</o:p><span style="text-align: center;"></span></p>

<p class="MsoNoSpacing">And this is the code:</p>

<p class="MsoNoSpacing"></p>

<div editor_component="code_highlighter" code_type="Java" title="" first_line="1" collapse="false" highlight="" nogutter="false" style="border:#666 1px dotted;border-left:#2AE 5px solid;padding:5px;background:#FAFAFA url('./modules/editor/components/code_highlighter/code.png') no-repeat top right;">import&nbsp;java.sql.Connection;<br />
import&nbsp;java.sql.DriverManager;<br />
import&nbsp;java.sql.SQLException;<br />
<br />
class&nbsp;Startup&nbsp;{<br />
&nbsp;&nbsp;public&nbsp;static&nbsp;void&nbsp;main(String&nbsp;args[])&nbsp;throws&nbsp;SQLException,&nbsp;ClassNotFoundException&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Load&nbsp;CUBRID&nbsp;JDBC&nbsp;driver<br />
&nbsp;&nbsp;&nbsp;&nbsp;Class.forName("cubrid.jdbc.driver.CUBRIDDriver");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Connect&nbsp;to&nbsp;the&nbsp;"demodb"&nbsp;database,&nbsp;with&nbsp;user&nbsp;"public"<br />
&nbsp;&nbsp;&nbsp;&nbsp;Connection&nbsp;connection&nbsp;=&nbsp;DriverManager.getConnection("jdbc:cubrid:localhost:30000:demodb:public::");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Get&nbsp;CUBRID&nbsp;JDBC&nbsp;driver&nbsp;info<br />
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println("CUBRID&nbsp;JDBC&nbsp;driver&nbsp;version&nbsp;is:&nbsp;"&nbsp;+&nbsp;connection.getMetaData().getDriverVersion());<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Cleanup<br />
&nbsp;&nbsp;&nbsp;&nbsp;connection.close();<br />
&nbsp;&nbsp;}<br />
}</div>&nbsp;<p></p>

<p class="MsoNoSpacing">As you can see, there’s nothing different in the above
code when compared to any other usual JDBC drivers – MySQL, PostgreSQL etc.</p>

<p class="MsoNoSpacing">When you run the code using the current CUBRID 9 release
as of this tutorial published date, you get this output:</p>

<p class="MsoNoSpacing"><i><span style="color:#44546A">CUBRID JDBC driver version is: 9.0.0.0478</span></i>&nbsp;</p>

<table class="MsoNormalTable" border="1" cellspacing="0" cellpadding="0" style="border: none;">
 <tbody><tr>
  <td width="623" valign="top" style="width:467.5pt;border:solid windowtext 1.0pt;
  mso-border-alt:solid windowtext .5pt;background:#FBE4D5;padding:0in 5.4pt 0in 5.4pt">
  <p class="MsoNoSpacing">You can find all the details about the CUBRID JDBC
  connection parameters <a href="/manual/841/en/Connection%20Configuration">here</a>.
  Remember, you can always specify username and password separately:</p>
  <p class="MsoNoSpacing"><o:p>&nbsp;</o:p><i><span style="color:#4472C4">&nbsp; &nbsp;String url =
  "jdbc:cubrid:localhost:33000:demodb:::";</span></i></p>
  <p class="MsoNoSpacing"><i><span style="color:#4472C4">&nbsp;&nbsp;&nbsp; String userid
  = "public";<o:p></o:p></span></i></p>
  <p class="MsoNoSpacing"><i><span style="color:#4472C4">&nbsp;&nbsp;&nbsp; String
  password = "";<o:p></o:p></span></i></p>
  <p class="MsoNoSpacing"><i><span style="color:#4472C4">&nbsp;&nbsp;&nbsp; Connection
  connection = DriverManager.getConnection(url, userid, password);</span></i></p>

</tr></tbody></table>

<p class="MsoNoSpacing"><o:p>&nbsp;</o:p></p>

<p class="MsoNoSpacing"><span style="font-size:20.0pt">“<i>Hello, World!</i>” and the CUBRID extensions<o:p></o:p></span></p>

<p class="MsoNoSpacing"><o:p>&nbsp;</o:p></p>

<p class="MsoNoSpacing">Let’s go on further in the spirit of the <b>Hello, World!</b> (You can read some
interesting things about the “<i>Hello,
World</i>” programming fame on <a href="http://en.wikipedia.org/wiki/Hello_world_program">Wikipedia</a>).</p>

<p class="MsoNoSpacing">Look at the following two “<i>Hello, World!</i>” code snippets:</p>

<p class="MsoNoSpacing"><u>Code snippet 1</u></p>

<p class="MsoNoSpacing"></p>

<div editor_component="code_highlighter" code_type="Java" title="" first_line="1" collapse="false" highlight="" nogutter="false" style="border:#666 1px dotted;border-left:#2AE 5px solid;padding:5px;background:#FAFAFA url('./modules/editor/components/code_highlighter/code.png') no-repeat top right;">public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;args)&nbsp;throws&nbsp;SQLException,&nbsp;ClassNotFoundException&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Load&nbsp;the&nbsp;driver<br />
&nbsp;&nbsp;&nbsp;&nbsp;Class.forName("cubrid.jdbc.driver.CUBRIDDriver");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Connect&nbsp;to&nbsp;the&nbsp;"demodb"&nbsp;database,&nbsp;with&nbsp;user&nbsp;"public"<br />
&nbsp;&nbsp;&nbsp;&nbsp;Connection&nbsp;connection&nbsp;=&nbsp;DriverManager.getConnection("jdbc:cubrid:localhost:30000:demodb:public::");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;Statement&nbsp;stmt&nbsp;=&nbsp;connection.createStatement();<br />
&nbsp;&nbsp;&nbsp;&nbsp;ResultSet&nbsp;rs&nbsp;=&nbsp;stmt.executeQuery("select&nbsp;'Hello,&nbsp;World!'");<br />
&nbsp;&nbsp;&nbsp;&nbsp;rs.next();<br />
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(rs.getString(1));<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Cleanup<br />
&nbsp;&nbsp;&nbsp;&nbsp;rs.close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;stmt.close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;connection.close();<br />
}</div>&nbsp;<p></p>

<p class="MsoNoSpacing"><u>Code snippet 2<o:p></o:p></u></p>

<p class="MsoNoSpacing"></p>

<div editor_component="code_highlighter" code_type="Java" title="" first_line="1" collapse="false" highlight="" nogutter="false" style="border:#666 1px dotted;border-left:#2AE 5px solid;padding:5px;background:#FAFAFA url('./modules/editor/components/code_highlighter/code.png') no-repeat top right;">public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;args)&nbsp;throws&nbsp;SQLException,&nbsp;ClassNotFoundException&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Load&nbsp;the&nbsp;driver<br />
&nbsp;&nbsp;&nbsp;&nbsp;Class.forName("cubrid.jdbc.driver.CUBRIDDriver");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Connect&nbsp;to&nbsp;the&nbsp;"demodb"&nbsp;database,&nbsp;with&nbsp;user&nbsp;"public"<br />
&nbsp;&nbsp;&nbsp;&nbsp;CUBRIDConnection&nbsp;connection&nbsp;=&nbsp;(CUBRIDConnection)&nbsp;DriverManager.getConnection("jdbc:cubrid:localhost:30000:demodb:public::");<br />
&nbsp;&nbsp;&nbsp;&nbsp;CUBRIDStatement&nbsp;stmt&nbsp;=&nbsp;(CUBRIDStatement)&nbsp;connection.createStatement();<br />
&nbsp;&nbsp;&nbsp;&nbsp;CUBRIDResultSet&nbsp;rs&nbsp;=&nbsp;(CUBRIDResultSet)&nbsp;stmt.executeQuery("select&nbsp;'Hello,&nbsp;World!'");<br />
&nbsp;&nbsp;&nbsp;&nbsp;rs.next();<br />
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(rs.getString(1));<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Cleanup<br />
&nbsp;&nbsp;&nbsp;&nbsp;rs.close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;stmt.close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;connection.close();<br />
}</div>

<br /><p></p>

<p class="MsoNoSpacing">The question is: <u>what is the difference between them
two, from the end user perspective?</u></p>

<p class="MsoNoSpacing">When we execute them, we will get the same, identical
result:</p>

<p class="MsoNoSpacing" align="center" style="text-align:center"><img src="http://www.cubrid.org/files/attach/images/236657/487/581/result.png" alt="result.png" width="687" height="419" editor_component="image_link"/>
<br /></p>

<p class="MsoNoSpacing"><o:p>&nbsp;</o:p></p>

<p class="MsoNoSpacing"><o:p>&nbsp;</o:p>The answer is that there is no difference, and this is
because the <b>CUBRID JDBC driver is fully
compatible with the JDBC (2.0) standard</b> and unless you are you using some
CUBRID extensions (out of the JDBC standard), there will be no difference if
you use JDBC “generic” objects or CUBRID objects.</p>

<table class="MsoNormalTable" border="1" cellspacing="0" cellpadding="0" style="border: none;">
 <tbody><tr>
  <td width="623" valign="top" style="width:467.5pt;border:solid windowtext 1.0pt;
  mso-border-alt:solid windowtext .5pt;background:#FBE4D5;padding:0in 5.4pt 0in 5.4pt">
  <p class="MsoNoSpacing">We recommend using the JDBC standard/generic objects
  declaration whenever possible, especially when your application will have to
  deal with other databases beside CUBRID! Do not write dozens of <i>if-else</i>, it’s much better to use
  one-only-running-everywhere “generic” code.</p>
  
 </tr>
</tbody></table>

<p class="MsoNoSpacing"><o:p>&nbsp;</o:p>…So when do we really need to use the CUBRID specific
objects? The answer is that this is required when we are using the CUBRID-only
extensions. Let’s see a simple example – retrieve the <b>OID</b>. As you probably already know, the concept of <a href="/questions/235437">OID</a> is specific only to the
CUBRID RDBMS.</p>

<p class="MsoNoSpacing"><o:p>&nbsp;</o:p></p>

<div editor_component="code_highlighter" code_type="Java" title="" first_line="1" collapse="false" highlight="" nogutter="false" style="border:#666 1px dotted;border-left:#2AE 5px solid;padding:5px;background:#FAFAFA url('./modules/editor/components/code_highlighter/code.png') no-repeat top right;">public&nbsp;static&nbsp;void&nbsp;main(String[]&nbsp;args)&nbsp;throws&nbsp;SQLException,&nbsp;ClassNotFoundException&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Load&nbsp;the&nbsp;driver<br />
&nbsp;&nbsp;&nbsp;&nbsp;Class.forName("cubrid.jdbc.driver.CUBRIDDriver");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Connect&nbsp;to&nbsp;the&nbsp;"demodb"&nbsp;database,&nbsp;with&nbsp;user&nbsp;"public"<br />
&nbsp;&nbsp;&nbsp;&nbsp;CUBRIDConnection&nbsp;connection&nbsp;=&nbsp;(CUBRIDConnection)&nbsp;DriverManager.getConnection("jdbc:cubrid:localhost:30000:demodb:public::");<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;CUBRIDStatement&nbsp;stmt&nbsp;=&nbsp;(CUBRIDStatement)&nbsp;connection.createStatement();<br />
&nbsp;&nbsp;&nbsp;&nbsp;CUBRIDResultSet&nbsp;rs&nbsp;=&nbsp;(CUBRIDResultSet)&nbsp;stmt.executeQuery("select&nbsp;event&nbsp;from&nbsp;event");<br />
&nbsp;&nbsp;&nbsp;&nbsp;rs.next();<br />
&nbsp;&nbsp;&nbsp;&nbsp;CUBRIDOID&nbsp;oid&nbsp;=&nbsp;rs.getOID(1);<br />
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(oid.getOidString()&nbsp;+&nbsp;"&nbsp;::&nbsp;"&nbsp;+&nbsp;oid.getTableName());<br />
&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Cleanup<br />
&nbsp;&nbsp;&nbsp;&nbsp;rs.close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;stmt.close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;connection.close();<br />
}</div>

<p></p>

<p class="MsoNoSpacing">The code output is:</p>

<p class="MsoNoSpacing"><o:p>&nbsp;</o:p><i><span style="color:#44546A">@570|1|0 :: event</span></i></p>

<p class="MsoNoSpacing"><o:p>&nbsp;</o:p>As expected, <b>@570|1|0</b>
is the OID corresponding to the first row returned in the <b>demodb</b> event table:</p>

<p class="MsoNoSpacing" style="text-align: center;"><o:p>&nbsp;</o:p><img src="http://www.cubrid.org/files/attach/images/236657/487/581/OID.png" alt="OID.png" width="665" height="392" editor_component="image_link" style="text-align: center;"/><span style="text-align: center;"></span></p>

<p class="MsoNoSpacing">Btw, detailed information about the rules of using OIDs
in Java can be found <a href="/manual/90/en/JDBC%20Programming#oid">here</a>.</p>

<table class="MsoNormalTable" border="1" cellspacing="0" cellpadding="0" style="border: none;">
 <tbody><tr>
  <td width="623" valign="top" style="width:467.5pt;border:solid windowtext 1.0pt;
  mso-border-alt:solid windowtext .5pt;background:#FBE4D5;padding:0in 5.4pt 0in 5.4pt">
  <p class="MsoNoSpacing">Please note that the JDBC driver has a place of its own
  in the CUBRID manual: <a href="/manual/90/en/JDBC%20Driver">http://www.cubrid.org/manual/90/en/JDBC%20Driver</a>.
  You will find there documentation, code samples and many other interesting
  things which are not listed in the standard tutorials cubrid.org web site
  section.</p>
  
 </tr>
</tbody></table>

<p class="MsoNoSpacing">Of course, the question you are probably asking yourself
now is: <u>what are the other CUBRID extensions available, besides OIDs?</u></p>

<p class="MsoNoSpacing">The quick answer is:</p>

<ul>
<li>Remember the specific CUBRID data types? For example, set, multiset, BLOB etc.? Obviously, there are CUBRID extensions to deal with them.</li>
<li>There is a <i>Java.sql.CUBRIDException</i> implementation</li>
<li>There are some other extensions as well - more information can be found <a href="/manual/841/en/CUBRID%20JDBC%20Interface">here</a>.</li>
</ul>

<p class="MsoNoSpacing">And we encourage you to take a look (and contribute!) at
the <a href="http://sourceforge.net/projects/cubrid/files/CUBRID-Drivers/JDBC_Driver/">driver
code</a>; <b>as with everything in the
CUBRID world, the JDBC driver is open source!</b></p>

<p class="MsoNoSpacing">&nbsp;</p>

<p class="MsoNoSpacing"><span style="font-size:20.0pt">Querying metadata<o:p></o:p></span></p>

<p class="MsoNoSpacing"><br /></p>

<p class="MsoNoSpacing">Many times the user need to query metadata… …schema info,
query information and so on. The JDBC API standard already provides a powerful
interface to deal with this. Let’s do a quick test on CUBRID:</p>

<p class="MsoNoSpacing"></p>

<div editor_component="code_highlighter" code_type="Java" title="" first_line="1" collapse="false" highlight="" nogutter="false" style="border:#666 1px dotted;border-left:#2AE 5px solid;padding:5px;background:#FAFAFA url('./modules/editor/components/code_highlighter/code.png') no-repeat top right;">DatabaseMetaData&nbsp;meta&nbsp;=&nbsp;connection.getMetaData();<br />
System.out.println();<br />
System.out.println("Database&nbsp;Product&nbsp;name&nbsp;is:&nbsp;"&nbsp;+&nbsp;meta.getDatabaseProductName());<br />
System.out.println("Database&nbsp;Product&nbsp;version&nbsp;is:&nbsp;"&nbsp;+&nbsp;meta.getDatabaseProductVersion());<br />
System.out.println("CUBRID&nbsp;JDBC&nbsp;Driver&nbsp;name&nbsp;is:&nbsp;"&nbsp;+&nbsp;meta.getDriverName());<br />
System.out.println("Database&nbsp;features:");<br />
System.out.println(String.format("&nbsp;-&nbsp;Stores&nbsp;mixed&nbsp;case&nbsp;identifiers:&nbsp;%s",&nbsp;meta.storesMixedCaseIdentifiers()));<br />
System.out.println(String.format("&nbsp;-&nbsp;Supports&nbsp;the&nbsp;ANSI92&nbsp;entry&nbsp;level&nbsp;SQL&nbsp;grammar:&nbsp;%s",&nbsp;meta.supportsANSI92EntryLevelSQL()));<br />
System.out.println(String.format("&nbsp;-&nbsp;Supports&nbsp;the&nbsp;ANSI92&nbsp;full&nbsp;level&nbsp;SQL&nbsp;grammar:&nbsp;%s",&nbsp;meta.supportsANSI92FullSQL()));<br />
System.out.println(String.format("&nbsp;-&nbsp;Supports&nbsp;transactions:&nbsp;%s",&nbsp;meta.supportsTransactions()));</div>

<br /><p></p>

<p class="MsoNoSpacing"><o:p>&nbsp;</o:p>Running this code for CUBRID 9.0 will return the
following result:</p>

<p class="MsoNoSpacing"><o:p>&nbsp;</o:p><i><span style="color:#44546A">Database Product name is: CUBRID</span></i></p>

<p class="MsoNoSpacing"><i><span style="color:#44546A">Database Product version is: 9.0.0.0478<o:p></o:p></span></i></p>

<p class="MsoNoSpacing"><i><span style="color:#44546A">CUBRID JDBC Driver name is: CUBRID JDBC Driver<o:p></o:p></span></i></p>

<p class="MsoNoSpacing"><i><span style="color:#44546A">Database features:<o:p></o:p></span></i></p>

<p class="MsoNoSpacing"><i><span style="color:#44546A">&nbsp;- Stores mixed
case identifiers: false<o:p></o:p></span></i></p>

<p class="MsoNoSpacing"><i><span style="color:#44546A">&nbsp;- Supports the
ANSI92 entry level SQL grammar: true<o:p></o:p></span></i></p>

<p class="MsoNoSpacing"><i><span style="color:#44546A">&nbsp;- Supports the
ANSI92 full level SQL grammar: false<o:p></o:p></span></i></p>

<p class="MsoNoSpacing"><i><span style="color:#44546A">&nbsp;- Supports
transactions: true<o:p></o:p></span></i></p>

<p class="MsoNoSpacing"><o:p>&nbsp;</o:p></p>

<p class="MsoNoSpacing">But more interesting would be to check some CUBRID
specifics, right...? As it turns out, there is actually a CUBRID extension in
the driver for this – <a href="/manual/840/en/CUBRIDResultSetMetaData">CUBRIDResultSetMetadata</a>:</p>

<p class="MsoNoSpacing"></p>

<div editor_component="code_highlighter" code_type="Java" title="" first_line="1" collapse="false" highlight="" nogutter="false" style="border:#666 1px dotted;border-left:#2AE 5px solid;padding:5px;background:#FAFAFA url('./modules/editor/components/code_highlighter/code.png') no-repeat top right;">//&nbsp;Create&nbsp;test&nbsp;table<br />
stmt.execute("drop&nbsp;table&nbsp;if&nbsp;exists&nbsp;test_metadata");<br />
stmt.execute("create&nbsp;table&nbsp;test_metadata(id&nbsp;int,&nbsp;seq&nbsp;set(int))");<br />
<br />
//&nbsp;Query&nbsp;table&nbsp;metadata<br />
ResultSet&nbsp;rs&nbsp;=&nbsp;stmt.executeQuery("select&nbsp;*&nbsp;from&nbsp;test_metadata");<br />
System.out.println("Element&nbsp;type:"&nbsp;+&nbsp;((CUBRIDResultSetMetaData)&nbsp;rs.getMetaData()).getElementType(2));<br />
System.out.println("Element&nbsp;type&nbsp;name:&nbsp;"&nbsp;+&nbsp;((CUBRIDResultSetMetaData)&nbsp;rs.getMetaData()).getElementTypeName(2));</div>&nbsp;<p></p>

<p class="MsoNoSpacing">The result of the code above is:</p>

<p class="MsoNoSpacing"><i><span style="color:#44546A">Element type:4</span></i></p>

<p class="MsoNoSpacing"><i><span style="color:#44546A">Element type name: INTEGER<o:p></o:p></span></i></p>

<p class="MsoNoSpacing">&nbsp;</p>

<p class="MsoNoSpacing"><span style="font-size:20.0pt">…So what happened to GLO…?<o:p></o:p></span></p>

<p class="MsoNoSpacing"><br /></p>

<p class="MsoNoSpacing">At the end of this first part of the tutorial, let’s
clarify what happened to the GLO data type, which we featured in the previous
tutorial. Well, just in case you missed this, the GLO data type has been
discontinued since 8.4.0 CUBRID release and it was replaced with <a href="/wiki_apis/entry/cubrid-lobs">LOB</a> data types
(BLOB, CLOB). As for how to use the new data types in Java, there are already
some examples published online – see <a href="/wiki_tutorials/entry/inserting-a-blob-file-to-a-cubrid-database">http://www.cubrid.org/wiki_tutorials/entry/inserting-a-blob-file-to-a-cubrid-database</a>.</p>

<p class="MsoNoSpacing">Let’s extend those examples with one more – let’s insert
and retrieve an image file into a BLOB field. Obviously, as we are dealing with
CUBRID specific extensions, which are not part of the JDBC API standards, we
will have to use non-generic JDBC objects.</p>

<p class="MsoNoSpacing"><u>Inserting the image:</u></p>

<p class="MsoNoSpacing"></p>

<div editor_component="code_highlighter" code_type="Java" title="" first_line="1" collapse="false" highlight="" nogutter="false" style="border:#666 1px dotted;border-left:#2AE 5px solid;padding:5px;background:#FAFAFA url('./modules/editor/components/code_highlighter/code.png') no-repeat top right;">//&nbsp;Read&nbsp;the&nbsp;file&nbsp;content<br />
FileInputStream&nbsp;inputFile&nbsp;=&nbsp;new&nbsp;FileInputStream("CUBRID.jpg");<br />
<br />
//&nbsp;Insert&nbsp;the&nbsp;file&nbsp;into&nbsp;the&nbsp;BLOB&nbsp;field<br />
String&nbsp;sql&nbsp;=&nbsp;"insert&nbsp;into&nbsp;test_blob&nbsp;values(?)";<br />
CUBRIDPreparedStatement&nbsp;insert_stmt&nbsp;=&nbsp;(CUBRIDPreparedStatement)&nbsp;connection.prepareStatement(sql);&nbsp;<br />
insert_stmt.setBlob(1,&nbsp;inputFile);<br />
insert_stmt.execute();<br />
insert_stmt.close();<br />
inputFile.close();</div>&nbsp;<p></p>

<p class="MsoNoSpacing"><u>Retrieving the image:<o:p></o:p></u></p>

<p class="MsoNoSpacing"></p>

<div editor_component="code_highlighter" code_type="Java" title="" first_line="1" collapse="false" highlight="" nogutter="false" style="border:#666 1px dotted;border-left:#2AE 5px solid;padding:5px;background:#FAFAFA url('./modules/editor/components/code_highlighter/code.png') no-repeat top right;">String&nbsp;sql&nbsp;=&nbsp;"select&nbsp;image&nbsp;from&nbsp;test_blob";<br />
Statement&nbsp;stmt&nbsp;=&nbsp;connection.createStatement();<br />
CUBRIDResultSet&nbsp;rs&nbsp;=&nbsp;(CUBRIDResultSet)stmt.executeQuery(sql);<br />
rs.next();<br />
CUBRIDBlob&nbsp;bImage&nbsp;=&nbsp;(CUBRIDBlob)&nbsp;rs.getBlob(1);<br />
byte[]&nbsp;bArray&nbsp;=&nbsp;bImage.getBytes(1,&nbsp;(int)bImage.length());<br />
<br />
//&nbsp;Write&nbsp;the&nbsp;BLOB&nbsp;data&nbsp;to&nbsp;file<br />
FileOutputStream&nbsp;outputFile&nbsp;=&nbsp;new&nbsp;FileOutputStream("CUBRID_out.jpg");<br />
outputFile.write(bArray);<br />
outputFile.close();</div>&nbsp;<p></p>

<p class="MsoNoSpacing"><span style="font-size:20.0pt">References and links</span></p>

<table class="MsoNormalTable" border="1" cellspacing="0" cellpadding="0" style="border: none;">
 <tbody><tr>
  <td width="252" valign="top" style="width: 189pt; border-top-style: solid; border-bottom-style: solid; border-left-style: solid; border-color: windowtext; border-width: 1pt; padding: 0in 5.4pt;">
  <p class="MsoNoSpacing">Driver downloads</p>
  </td>
  <td width="371" valign="top" style="width:278.5pt;border:solid windowtext 1.0pt;
  border-left:none;mso-border-left-alt:solid windowtext .5pt;mso-border-alt:
  solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt">
  <p class="MsoNoSpacing"><a href="/?mid=downloads&amp;item=jdbc_driver">http://www.cubrid.org/?mid=downloads&amp;item=jdbc_driver</a>
  </p>
  
 </tr>
 <tr>
  <td width="252" valign="top" style="width: 189pt; border-bottom-style: solid; border-left-style: solid; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; border-top-style: none; padding: 0in 5.4pt;">
  <p class="MsoNoSpacing">Driver home page</p>
  </td>
  <td width="371" valign="top" style="width:278.5pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt">
  <p class="MsoNoSpacing"><a href="/wiki_apis/entry/about-cubrid-jdbc-driver">http://www.cubrid.org/wiki_apis/entry/about-cubrid-jdbc-driver</a>
  </p>
  
 </tr>
 <tr>
  <td width="252" valign="top" style="width: 189pt; border-bottom-style: solid; border-left-style: solid; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; border-top-style: none; padding: 0in 5.4pt;">
  <p class="MsoNoSpacing">Tutorials and Guides</p>
  </td>
  <td width="371" valign="top" style="width:278.5pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt">
  <p class="MsoNoSpacing"><a href="/wiki_apis/entry/cubrid-jdbc-tutorials">http://www.cubrid.org/wiki_apis/entry/cubrid-jdbc-tutorials</a>
  </p>
  
 </tr>
 <tr>
  <td width="252" valign="top" style="width: 189pt; border-bottom-style: solid; border-left-style: solid; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; border-top-style: none; padding: 0in 5.4pt;">
  <p class="MsoNoSpacing">CUBRID Q&amp;A</p>
  </td>
  <td width="371" valign="top" style="width:278.5pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt">
  <p class="MsoNoSpacing"><a href="/questions">http://www.cubrid.org/questions</a>
  </p>
  
 </tr>
 <tr>
  <td width="252" valign="top" style="width: 189pt; border-bottom-style: solid; border-left-style: solid; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; border-top-style: none; padding: 0in 5.4pt;">
  <p class="MsoNoSpacing">CUBRID JDBC API documentation</p>
  </td>
  <td width="371" valign="top" style="width:278.5pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt">
  <p class="MsoNoSpacing"><a href="/manual/840/en/JDBC%20API">http://www.cubrid.org/manual/840/en/JDBC%20API</a>
  </p>
  
 </tr>
 <tr>
  <td width="252" valign="top" style="width: 189pt; border-bottom-style: solid; border-left-style: solid; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; border-top-style: none; padding: 0in 5.4pt;">
  <p class="MsoNoSpacing">JDBC 2.0 standard</p>
  </td>
  <td width="371" valign="top" style="width:278.5pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt">
  <p class="MsoNoSpacing"><a href="http://www.karunya.edu/cse/collaboration/sun/resources/jdbc20.stdext.pdf">http://www.karunya.edu/cse/collaboration/sun/resources/jdbc20.stdext.pdf</a>
  </p>
  
 </tr>
 <tr>
  <td width="252" valign="top" style="width: 189pt; border-bottom-style: solid; border-left-style: solid; border-right-color: windowtext; border-bottom-color: windowtext; border-left-color: windowtext; border-right-width: 1pt; border-bottom-width: 1pt; border-left-width: 1pt; border-top-style: none; padding: 0in 5.4pt;">
  <p class="MsoNoSpacing">Source code</p>
  </td>
  <td width="371" valign="top" style="width:278.5pt;border-top:none;border-left:
  none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
  mso-border-top-alt:solid windowtext .5pt;mso-border-left-alt:solid windowtext .5pt;
  mso-border-alt:solid windowtext .5pt;padding:0in 5.4pt 0in 5.4pt">
  <p class="MsoNoSpacing"><a href="http://sourceforge.net/projects/cubrid/files/CUBRID-Drivers/JDBC_Driver/">http://sourceforge.net/projects/cubrid/files/CUBRID-Drivers/JDBC_Driver/</a></p>

</tr></tbody></table>

<p class="MsoNoSpacing">If you would like to get the code we used in this
tutorial, as well as the IntelliJ project – please contact us at: <a href="/contact">http://www.cubrid.org/contact</a>.</p>

<p class="MsoNoSpacing" align="center" style="text-align:center"><img src="http://www.cubrid.org/files/attach/images/236657/487/581/Project.png" alt="Project.png" width="573" height="341" editor_component="image_link"/>
<br /></p>

<p class="MsoNoSpacing">We hope you enjoyed this tutorial!
The 2<sup>nd</sup> part will be available soon.</p>

<p class="MsoNoSpacing">Please let us know your feedback and suggestions, so we
can improve!</p>

<p class="MsoNoSpacing">And remember to stay tuned for more tutorials to come…</p>

<p class="MsoNoSpacing"><b>Thank you!</b></p>

<p class="MsoNoSpacing">The CUBRID API team</p>

<p></p>]]></description>
                        <pubDate>Mon, 11 Feb 2013 03:35:12 -0800</pubDate>
                        <category>jdbc</category>
                        <category>tutorial</category>
                        <category>driver</category>
                                </item>
            </channel>
</rss>
