<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2837485492691527529</id><updated>2024-12-19T09:00:39.431+05:30</updated><category term="java.sql"/><category term="Examples"/><category term="INTRODUCTION"/><category term="JAVA APPLET"/><category term="java.awt"/><category term="java.net"/><category term="java.beans"/><category term="JAVA String Utility"/><category term="Arrays"/><category term="java.math"/><category term="java.util.regex"/><category term="Sort"/><category term="Swing"/><category term="java.security"/><category term="java.util.zip"/><category term="Catching Exceptions"/><category term="Classes and Objects"/><category term="Core Java Programs-part 1"/><category term="Core Java Programs-part 2"/><category term="Core Java Programs-part3"/><category term="Criticism of Java programming language"/><category term="Falling Letters"/><category term="File I/O and Streams"/><category term="Fun With Letters and Words"/><category term="Get current working directory"/><category term="How do I convert String to Date object?"/><category term="How do I convert string into InputStream?"/><category term="How do i calculate directory size?"/><category term="How to make executable jar files in JDK1.3.1?"/><category term="Interfaces"/><category term="JAVA Date Utility"/><category term="Java Arithmetic Operators"/><category term="Java Assignment Operators"/><category term="Java Boolean Operators"/><category term="Java Command Line Arguments"/><category term="Java Comments"/><category term="Java Conditional Operators"/><category term="Java Data and Variables"/><category term="Java Hello World Program"/><category term="Java If-Else Statement"/><category term="Java Increment and Decrement Operators"/><category term="Java Loops (while"/><category term="Java Relational Operators"/><category term="Java Variables and Arithmetic Expressions"/><category term="Java Virtual Machine"/><category term="Know the current position of cursor"/><category term="Letters"/><category term="Methods (Includes Recursive Methods)"/><category term="Rotating Lines"/><category term="Send an email with attachment"/><category term="Use for..each in Java"/><category term="What is Autoboxing?"/><category term="Write text file"/><category term="connection to database"/><category term="do-while and  for loops)"/><title type='text'>JAVA-MANI.BLOGSPOT.COM</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>118</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-2358154712281845969</id><published>2008-12-09T09:26:00.000+05:30</published><updated>2008-12-09T09:26:00.791+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>Get all table names from database</title><content type='html'>import java.sql.Connection;&lt;br /&gt;import java.sql.DatabaseMetaData;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.ResultSet;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt; &lt;br /&gt;public class GettingTableListExample {&lt;br /&gt; public static void main(String[] args) throws Exception {&lt;br /&gt;  Connection connection = null;&lt;br /&gt;  try {&lt;br /&gt;   Class.forName(&quot;oracle.jdbc.driver.OracleDriver&quot;);&lt;br /&gt;   String url = &quot;jdbc:oracle:thin:@localhost:1521:xe&quot;;&lt;br /&gt;   String username = &quot;kodejava&quot;;&lt;br /&gt;   String password = &quot;welcome&quot;;&lt;br /&gt;   connection = DriverManager.getConnection(url, username, password);&lt;br /&gt;   &lt;br /&gt;   // Gets the metadata of the database&lt;br /&gt;   DatabaseMetaData dbmd = connection.getMetaData();&lt;br /&gt;   String[] types = {&quot;TABLE&quot;};&lt;br /&gt;   &lt;br /&gt;   ResultSet rs = dbmd.getTables(null, null, &quot;%&quot;, types);&lt;br /&gt;   while (rs.next()) {&lt;br /&gt;    String tableCatalog = rs.getString(1);&lt;br /&gt;    String tableSchema = rs.getString(2);&lt;br /&gt;    String tableName = rs.getString(3);&lt;br /&gt;    &lt;br /&gt;    System.out.printf(&quot;%s - %s - %s%n&quot;, tableCatalog, tableSchema, tableName);&lt;br /&gt;   }&lt;br /&gt;  } catch (SQLException e) {&lt;br /&gt;   if (connection != null &amp;&amp; !connection.isClosed()) {&lt;br /&gt;    connection.close();&lt;br /&gt;   }&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/2358154712281845969/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/2358154712281845969' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/2358154712281845969'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/2358154712281845969'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/12/get-all-table-names-from-database.html' title='Get all table names from database'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-4214754292625421621</id><published>2008-12-07T09:22:00.000+05:30</published><updated>2008-12-07T09:22:01.145+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>Create a connection to MS Access database</title><content type='html'>Here is an example about how to create a database connection to MS Access database. To allow the database access to be authenticated the security user account can be add from Tools-&gt;Security-&gt;User and Group Accounts.&lt;br /&gt;&lt;br /&gt;On the example below we can either connect through the DSN created previously on the Windows system or we can create it in our program as the long URL below.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.sql.Connection;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt;import java.sql.PreparedStatement;&lt;br /&gt; &lt;br /&gt;public class MSAccessConnect {&lt;br /&gt;    //&lt;br /&gt;    // If you want to use you ODBC DSN&lt;br /&gt;    //&lt;br /&gt;    //private static final String URL = &quot;jdbc:odbc:TestDB&quot;;&lt;br /&gt; &lt;br /&gt;    private static final String USERNAME = &quot;admin&quot;;&lt;br /&gt;    private static final String PASSWORD = &quot;welcome&quot;;&lt;br /&gt;    private static final String DRIVER = &quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;;&lt;br /&gt; &lt;br /&gt;    private static final String URL =&lt;br /&gt;        &quot;jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\Database\\testdb.mdb;}&quot;;&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        Connection connection = null;&lt;br /&gt;        try {&lt;br /&gt;            Class.forName(DRIVER);&lt;br /&gt;            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);&lt;br /&gt; &lt;br /&gt;            //&lt;br /&gt;            // Do something with the connection here!&lt;br /&gt;            //&lt;br /&gt;        } catch (SQLException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } finally {&lt;br /&gt;            connection.close();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/4214754292625421621/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/4214754292625421621' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/4214754292625421621'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/4214754292625421621'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/12/create-connection-to-ms-access-database.html' title='Create a connection to MS Access database'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-271051337925081292</id><published>2008-12-05T09:14:00.001+05:30</published><updated>2008-12-05T09:14:01.169+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>make updates in Updatable ResultSet</title><content type='html'>Using an updatable resultset enable our program to update record in the database from the ResultSet object. The operation on the ResultSet object can be update, insert or delete. With this mechanism we can update database without executing an sql command.&lt;br /&gt;&lt;br /&gt;In the example below we have a product table with the id, product_code, product_name, quantity and price. In the first step after we load the resultset we update the product title of the first record. Then we move to the next record and delete it. At last we insert a new record to database.&lt;br /&gt;&lt;br /&gt;import java.sql.Connection;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.ResultSet;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt;import java.sql.Statement;&lt;br /&gt; &lt;br /&gt;public class UpdatableResultSetDemo {&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;        Connection connection = null;&lt;br /&gt; &lt;br /&gt;        try {&lt;br /&gt;            //&lt;br /&gt;            // Routine to get a connection object to database.&lt;br /&gt;            //&lt;br /&gt;            Class.forName(&quot;com.mysql.jdbc.Driver&quot;);&lt;br /&gt;            connection = DriverManager.getConnection(&quot;jdbc:mysql://localhost/testdb&quot;,&lt;br /&gt;                    &quot;root&quot;, &quot;&quot;);&lt;br /&gt; &lt;br /&gt;            //&lt;br /&gt;            // Create an updatable resultset. It means that instead of using a&lt;br /&gt;            // separate sql comment to update the data we can update it directly&lt;br /&gt;            // in the resultset object.&lt;br /&gt;            //&lt;br /&gt;            // What makes it updatable is because when creating the statement we&lt;br /&gt;            // ask the connection object to create statement with CONCUR_UPDATABLE.&lt;br /&gt;            // The updatable doesn&#39;t need to be TYPE_SCROLL_SENSITIVE, but adding&lt;br /&gt;            // this parameter to the statement enable us to go back and forth to&lt;br /&gt;            // update the data.&lt;br /&gt;            //&lt;br /&gt;            Statement statement = connection.createStatement(&lt;br /&gt;                    ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);&lt;br /&gt; &lt;br /&gt;            String query = &quot;SELECT id, product_code, product_name, quantity, price FROM products&quot;;&lt;br /&gt;            ResultSet uprs = statement.executeQuery(query);&lt;br /&gt; &lt;br /&gt;            System.out.println(&quot;id\tcode\tname\tquantity\tquantity\tprice&quot;);&lt;br /&gt;            while (uprs.next()) {&lt;br /&gt;                System.out.println(uprs.getString(&quot;id&quot;) + &quot;\t&quot;&lt;br /&gt;                        + uprs.getString(&quot;product_code&quot;) + &quot;\t&quot;&lt;br /&gt;                        + uprs.getString(&quot;product_name&quot;) + &quot;\t&quot;&lt;br /&gt;                        + uprs.getInt(&quot;quantity&quot;) + &quot;\t&quot;&lt;br /&gt;                        + uprs.getDouble(&quot;price&quot;));&lt;br /&gt;            }&lt;br /&gt; &lt;br /&gt;            //&lt;br /&gt;            // Move to the first row and update the resultset data. After we&lt;br /&gt;            // update the rowset value we call the updateRow() method to update&lt;br /&gt;            // the data in the database.&lt;br /&gt;            //&lt;br /&gt;            uprs.first();&lt;br /&gt;            uprs.updateString(&quot;product_name&quot;, &quot;UML Distilled 3rd Edition&quot;);&lt;br /&gt;            uprs.updateRow();&lt;br /&gt; &lt;br /&gt;            //&lt;br /&gt;            // Move to the next resultset row and delete the row in the resultset&lt;br /&gt;            // and apply it to the database.&lt;br /&gt;            //&lt;br /&gt;            uprs.next();&lt;br /&gt;            uprs.deleteRow();&lt;br /&gt; &lt;br /&gt;            //&lt;br /&gt;            // Insert a new row in the resultset object with the moveToInsertRow()&lt;br /&gt;            // method. Supply the information to be inserted and finally call the&lt;br /&gt;            // insertRow() method to insert record to the database.&lt;br /&gt;            //&lt;br /&gt;            uprs.moveToInsertRow();&lt;br /&gt;            uprs.updateString(&quot;product_code&quot;, &quot;P0000010&quot;);&lt;br /&gt;            uprs.updateString(&quot;product_name&quot;, &quot;Data Structures, Algorithms&quot;);&lt;br /&gt;            uprs.updateInt(&quot;quantity&quot;, 10);&lt;br /&gt;            uprs.updateDouble(&quot;price&quot;, 50.99);&lt;br /&gt;            uprs.insertRow();&lt;br /&gt; &lt;br /&gt;            uprs.beforeFirst();&lt;br /&gt;            System.out.println(&quot;id\tcode\tname\tquantity\tquantity\tprice&quot;);&lt;br /&gt;            while (uprs.next()) {&lt;br /&gt;                System.out.println(uprs.getString(&quot;id&quot;) + &quot;\t&quot;&lt;br /&gt;                        + uprs.getString(&quot;product_code&quot;) + &quot;\t&quot;&lt;br /&gt;                        + uprs.getString(&quot;product_name&quot;) + &quot;\t&quot;&lt;br /&gt;                        + uprs.getInt(&quot;quantity&quot;) + &quot;\t&quot;&lt;br /&gt;                        + uprs.getDouble(&quot;price&quot;));&lt;br /&gt;            }&lt;br /&gt;        } catch (ClassNotFoundException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } catch (SQLException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } finally {&lt;br /&gt;            try {&lt;br /&gt;                connection.close();&lt;br /&gt;            } catch (SQLException e) {&lt;br /&gt;                e.printStackTrace();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/271051337925081292/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/271051337925081292' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/271051337925081292'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/271051337925081292'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/12/make-updates-in-updatable-resultset.html' title='make updates in Updatable ResultSet'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-660948611952773566</id><published>2008-12-03T09:20:00.001+05:30</published><updated>2008-12-03T09:20:00.129+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>How do I know if a table column can have a null value or not?</title><content type='html'>In this example we&#39;ll show how to use ResultSetMetaData.isNullable() method to know if a column can be null or not. This method return an integer which values defined in the constants of ResultSetMetaData.columnNullable, ResultSetMetaData.columnNoNulls and ResultSetMetaData.columnNullableUnknown.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.sql.Connection;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.ResultSet;&lt;br /&gt;import java.sql.ResultSetMetaData;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt;import java.sql.Statement;&lt;br /&gt; &lt;br /&gt;public class IsNullableExample {&lt;br /&gt;    private static final String DRIVER = &quot;com.mysql.jdbc.Driver&quot;;&lt;br /&gt;    private static final String URL = &quot;jdbc:mysql://localhost/testdb&quot;;&lt;br /&gt;    private static final String USERNAME = &quot;root&quot;;&lt;br /&gt;    private static final String PASSWORD = &quot;&quot;;&lt;br /&gt;    &lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt; Connection connection = null;&lt;br /&gt; try {&lt;br /&gt;     Class.forName(DRIVER);     &lt;br /&gt;     connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);&lt;br /&gt;     &lt;br /&gt;     Statement statement = connection.createStatement();&lt;br /&gt;     ResultSet resultSet = statement.executeQuery(&quot;SELECT id, username FROM users&quot;);&lt;br /&gt;     &lt;br /&gt;     //&lt;br /&gt;     // The ResultSetMetaData is where all metadata related information&lt;br /&gt;     // for a result set is stored.&lt;br /&gt;     //&lt;br /&gt;     ResultSetMetaData metadata = resultSet.getMetaData();         &lt;br /&gt;     int nullability = metadata.isNullable(1);&lt;br /&gt;     &lt;br /&gt;     //&lt;br /&gt;     // Check the nullability status of a column (ID)&lt;br /&gt;     //&lt;br /&gt;     if (nullability == ResultSetMetaData.columnNullable) {&lt;br /&gt;  System.out.println(&quot;Columns ID can have a null value&quot;);&lt;br /&gt;     } else if (nullability == ResultSetMetaData.columnNoNulls) {&lt;br /&gt;  System.out.println(&quot;Columns ID does not allowed to have a null value&quot;);&lt;br /&gt;     } else if (nullability == ResultSetMetaData.columnNullableUnknown) {&lt;br /&gt;  System.out.println(&quot;Nullability unknown&quot;);  &lt;br /&gt;     }&lt;br /&gt; } catch (SQLException e) {&lt;br /&gt;     e.printStackTrace();&lt;br /&gt; } finally {&lt;br /&gt;     connection.close();&lt;br /&gt; }&lt;br /&gt;    }&lt;br /&gt;}</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/660948611952773566/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/660948611952773566' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/660948611952773566'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/660948611952773566'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/12/how-do-i-know-if-table-column-can-have.html' title='How do I know if a table column can have a null value or not?'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-8180793247854551535</id><published>2008-12-01T09:01:00.000+05:30</published><updated>2008-12-01T09:01:00.245+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>Get list of stored procedure names</title><content type='html'>import java.sql.*;&lt;br /&gt; &lt;br /&gt;public class StoredProcedureListExample {&lt;br /&gt;    private static String url = &quot;jdbc:oracle:thin:@localhost:1521:xe&quot;;&lt;br /&gt;    private static String username = &quot;kodejava&quot;;&lt;br /&gt;    private static String password = &quot;welcome&quot;;&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) throws Exception{&lt;br /&gt;        Connection conn = getConnection();&lt;br /&gt; &lt;br /&gt;        try {&lt;br /&gt;            DatabaseMetaData metadata = conn.getMetaData();&lt;br /&gt;            ResultSet result = metadata.getProcedures(null, &quot;KODEJAVA&quot;, &quot;%&quot;);&lt;br /&gt;            while (result.next()) {&lt;br /&gt;                System.out.println(result.getString(&quot;PROCEDURE_CAT&quot;)&lt;br /&gt;                        + &quot; - &quot; + result.getString(&quot;PROCEDURE_SCHEM&quot;)&lt;br /&gt;                        + &quot; - &quot; + result.getString(&quot;PROCEDURE_NAME&quot;));&lt;br /&gt;            }&lt;br /&gt;        } catch (Exception e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } finally {&lt;br /&gt;            closeConnection(conn);&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    private static Connection getConnection() throws Exception{&lt;br /&gt;        Connection conn = null;&lt;br /&gt;        try {&lt;br /&gt;            Class.forName(&quot;oracle.jdbc.driver.OracleDriver&quot;);&lt;br /&gt;            conn = DriverManager.getConnection(url, username, password);&lt;br /&gt;        } catch (ClassNotFoundException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;            throw new Exception(e);&lt;br /&gt;        } catch (SQLException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;            throw new Exception(e);&lt;br /&gt;        }&lt;br /&gt;        return conn;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    private static void closeConnection(Connection conn) throws SQLException {&lt;br /&gt;        if (conn != null &amp;&amp; !conn.isClosed()) {&lt;br /&gt;            conn.close();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/8180793247854551535/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/8180793247854551535' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/8180793247854551535'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/8180793247854551535'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/12/get-list-of-stored-procedure-names.html' title='Get list of stored procedure names'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-2729521908867965541</id><published>2008-11-29T09:04:00.000+05:30</published><updated>2008-11-29T09:04:00.540+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>How do I execute stored procedure?</title><content type='html'>Stored procedure are user-generated functions or procedures that, once created in the database, can be called by the client applications, such as Java application. In this example we&#39;ll demonstrate how to use the JDBC java.sql.CallableStatement to call a stored procedure.&lt;br /&gt;&lt;br /&gt;The store procedure in this example is just for inserting a record into table. Just like the PreparedStatement interface, in the CallableStatement we can pass the parameter to the procedure by calling the appropriate setXXX(index, value) method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.sql.CallableStatement;&lt;br /&gt;import java.sql.Connection;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt; &lt;br /&gt;public class CallableStatementDemo {&lt;br /&gt;    private static String url = &quot;jdbc:oracle:thin:@localhost:1521:xe&quot;;&lt;br /&gt;    private static String username = &quot;kodejava&quot;;&lt;br /&gt;    private static String password = &quot;welcome&quot;;&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        Connection conn = null;&lt;br /&gt;        try {&lt;br /&gt;            Class.forName(&quot;oracle.jdbc.driver.OracleDriver&quot;);&lt;br /&gt;            conn = DriverManager.getConnection(url, username, password);&lt;br /&gt; &lt;br /&gt;            //&lt;br /&gt;            // Create a CallableStatement to execute the CREATE_USERS procedure&lt;br /&gt;            // &lt;br /&gt;            CallableStatement stmt = conn.prepareCall(&quot;{call CREATE_USERS (?, ?, ?, ?, ?, ?)}&quot;);&lt;br /&gt; &lt;br /&gt;            //&lt;br /&gt;            // Defines all the required parameter values.&lt;br /&gt;            // &lt;br /&gt;            stmt.setString(1, &quot;kodejava&quot;);&lt;br /&gt;            stmt.setString(2, &quot;welcome&quot;);&lt;br /&gt;            stmt.setString(3, &quot;Kode&quot;);&lt;br /&gt;            stmt.setString(4, &quot;Java&quot;);&lt;br /&gt;            stmt.setString(5, &quot;Denpasar - Bali&quot;);&lt;br /&gt;            stmt.setString(6, &quot;webmaster[at]kodejava[.]org&quot;);&lt;br /&gt;            stmt.execute();&lt;br /&gt;        } catch (SQLException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } finally {&lt;br /&gt;            if (conn != null &amp;&amp; !conn.isClosed()) {&lt;br /&gt;                conn.close();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;&lt;br /&gt;Below is the stored procedure that was executed in the code above.&lt;br /&gt;&lt;br /&gt;CREATE OR REPLACE PROCEDURE CREATE_USERS (username IN VARCHAR2, password IN VARCHAR2, firstName IN VARCHAR2, lastName IN VARCHAR2, address IN VARCHAR2, email IN VARCHAR2) AS&lt;br /&gt;BEGIN&lt;br /&gt;    INSERT INTO users (username, password, first_name, last_name, address, email) VALUES (username, password, firstName, lastName, address, email);&lt;br /&gt;END CREATE_USERS;</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/2729521908867965541/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/2729521908867965541' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/2729521908867965541'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/2729521908867965541'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/11/how-do-i-execute-stored-procedure.html' title='How do I execute stored procedure?'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-5593430401589096513</id><published>2008-11-27T08:55:00.002+05:30</published><updated>2008-11-27T08:55:00.296+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>Get JDBC driver information</title><content type='html'>import java.sql.Connection;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.DatabaseMetaData;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt; &lt;br /&gt;public class DriverInfo {&lt;br /&gt;    private static final String DRIVER = &quot;com.mysql.jdbc.Driver&quot;;&lt;br /&gt;    private static final String URL = &quot;jdbc:mysql://localhost/kodejava&quot;;&lt;br /&gt;    private static final String USERNAME = &quot;root&quot;;&lt;br /&gt;    private static final String PASSWORD = &quot;&quot;;&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        Connection connection = null;&lt;br /&gt;        try {&lt;br /&gt;            Class.forName(DRIVER);&lt;br /&gt;            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);&lt;br /&gt; &lt;br /&gt;            DatabaseMetaData metadata = connection.getMetaData();&lt;br /&gt;            String driverName = metadata.getDriverName();&lt;br /&gt;            String driverVersion = metadata.getDriverVersion();&lt;br /&gt;            int majorVersion = metadata.getDriverMajorVersion();&lt;br /&gt;            int minorVersion = metadata.getDriverMinorVersion();&lt;br /&gt; &lt;br /&gt;            System.out.println(&quot;driverName = &quot; + driverName);&lt;br /&gt;            System.out.println(&quot;driverVersion = &quot; + driverVersion);&lt;br /&gt;            System.out.println(&quot;majorVersion = &quot; + majorVersion);&lt;br /&gt;            System.out.println(&quot;minorVersion = &quot; + minorVersion);&lt;br /&gt;        } catch (SQLException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } finally {&lt;br /&gt;            if (connection != null) {&lt;br /&gt;                connection.close();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;&lt;br /&gt;The result of our program:&lt;br /&gt;&lt;br /&gt;driverName = MySQL-AB JDBC Driver&lt;br /&gt;driverVersion = mysql-connector-java-5.0.3 ( $Date: 2006-07-26 17:26:47 +0200 (Wed, 26 Jul 2006) $, $Revision: 5553 $ )&lt;br /&gt;majorVersion = 5&lt;br /&gt;minorVersion = 0</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/5593430401589096513/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/5593430401589096513' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/5593430401589096513'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/5593430401589096513'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/11/get-jdbc-driver-information.html' title='Get JDBC driver information'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-5903375373936841938</id><published>2008-11-25T08:53:00.000+05:30</published><updated>2008-11-25T08:53:00.404+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>Get database product information</title><content type='html'>import java.sql.Connection;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.DatabaseMetaData;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt; &lt;br /&gt;public class DriverInfo {&lt;br /&gt;    private static final String DRIVER = &quot;com.mysql.jdbc.Driver&quot;;&lt;br /&gt;    private static final String URL = &quot;jdbc:mysql://localhost/kodejava&quot;;&lt;br /&gt;    private static final String USERNAME = &quot;root&quot;;&lt;br /&gt;    private static final String PASSWORD = &quot;&quot;;&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        Connection connection = null;&lt;br /&gt;        try {&lt;br /&gt;            Class.forName(DRIVER);&lt;br /&gt;            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);&lt;br /&gt; &lt;br /&gt;            DatabaseMetaData metadata = connection.getMetaData();&lt;br /&gt; &lt;br /&gt;            int majorVersion = metadata.getDatabaseMajorVersion();&lt;br /&gt;            System.out.println(&quot;majorVersion = &quot; + majorVersion);&lt;br /&gt;            &lt;br /&gt;            int minorVersion = metadata.getDatabaseMinorVersion();&lt;br /&gt;            System.out.println(&quot;minorVersion = &quot; + minorVersion);&lt;br /&gt; &lt;br /&gt;            String productName = metadata.getDatabaseProductName();&lt;br /&gt;            System.out.println(&quot;productName = &quot; + productName);&lt;br /&gt; &lt;br /&gt;            String productVersion = metadata.getDatabaseProductVersion();&lt;br /&gt;            System.out.println(&quot;productVersion = &quot; + productVersion);&lt;br /&gt;        } catch (SQLException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } finally {&lt;br /&gt;            if (connection != null) {&lt;br /&gt;                connection.close();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And here are the result:&lt;br /&gt;&lt;br /&gt;majorVersion = 5&lt;br /&gt;minorVersion = 0&lt;br /&gt;productName = MySQL&lt;br /&gt;productVersion = 5.0.51a</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/5903375373936841938/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/5903375373936841938' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/5903375373936841938'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/5903375373936841938'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/11/get-database-product-information.html' title='Get database product information'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-1152636315731274449</id><published>2008-11-23T08:51:00.000+05:30</published><updated>2008-11-23T08:51:00.966+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>How do I know if database support transaction</title><content type='html'>import java.sql.Connection;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.DatabaseMetaData;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt; &lt;br /&gt;public class SupportTransaction {&lt;br /&gt;    private static final String DRIVER = &quot;com.mysql.jdbc.Driver&quot;;&lt;br /&gt;    private static final String URL = &quot;jdbc:mysql://localhost/kodejava&quot;;&lt;br /&gt;    private static final String USERNAME = &quot;root&quot;;&lt;br /&gt;    private static final String PASSWORD = &quot;&quot;;&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        Connection connection = null;&lt;br /&gt;        try {&lt;br /&gt;            Class.forName(DRIVER);&lt;br /&gt;            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);&lt;br /&gt;            DatabaseMetaData metadata = connection.getMetaData();&lt;br /&gt; &lt;br /&gt;            boolean isSupportTransaction = metadata.supportsTransactions();&lt;br /&gt;            System.out.println(&quot;Support Transaction = &quot; + isSupportTransaction);&lt;br /&gt;        } catch (SQLException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } finally {&lt;br /&gt;            if (connection != null) {&lt;br /&gt;                connection.close();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/1152636315731274449/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/1152636315731274449' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/1152636315731274449'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/1152636315731274449'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/11/how-do-i-know-if-database-support_23.html' title='How do I know if database support transaction'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-8962127444135690768</id><published>2008-11-21T08:49:00.000+05:30</published><updated>2008-11-21T08:49:00.431+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>Get data types supported by database</title><content type='html'>import java.sql.DatabaseMetaData;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt;import java.sql.Connection;&lt;br /&gt;import java.sql.ResultSet;&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;public class DatabaseTypeInfo {&lt;br /&gt;    private static final String DRIVER = &quot;com.mysql.jdbc.Driver&quot;;&lt;br /&gt;    private static final String URL = &quot;jdbc:mysql://localhost/kodejava&quot;;&lt;br /&gt;    private static final String USERNAME = &quot;root&quot;;&lt;br /&gt;    private static final String PASSWORD = &quot;&quot;;&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        Connection connection = null;&lt;br /&gt;        ResultSet resultSet = null;&lt;br /&gt;        try {&lt;br /&gt;            Class.forName(DRIVER);&lt;br /&gt;            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);&lt;br /&gt; &lt;br /&gt;            DatabaseMetaData metadata = connection.getMetaData();&lt;br /&gt;            resultSet = metadata.getTypeInfo();&lt;br /&gt;            while (resultSet.next()) {&lt;br /&gt;                String typeName = resultSet.getString(&quot;TYPE_NAME&quot;);&lt;br /&gt;                System.out.println(&quot;Type Name = &quot; + typeName);&lt;br /&gt;            }&lt;br /&gt;        } catch (SQLException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } finally {&lt;br /&gt;            if (resultSet != null) {&lt;br /&gt;                resultSet.close();&lt;br /&gt;            }&lt;br /&gt;            if (connection != null) {&lt;br /&gt;                connection.close();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;Here are the data type support MySQL database:&lt;br /&gt;&lt;br /&gt;Type Name = BIT&lt;br /&gt;Type Name = BOOL&lt;br /&gt;Type Name = TINYINT&lt;br /&gt;Type Name = BIGINT&lt;br /&gt;Type Name = LONG VARBINARY&lt;br /&gt;Type Name = MEDIUMBLOB&lt;br /&gt;Type Name = LONGBLOB&lt;br /&gt;Type Name = BLOB&lt;br /&gt;Type Name = TINYBLOB&lt;br /&gt;Type Name = VARBINARY&lt;br /&gt;Type Name = BINARY&lt;br /&gt;Type Name = LONG VARCHAR&lt;br /&gt;Type Name = MEDIUMTEXT&lt;br /&gt;Type Name = LONGTEXT&lt;br /&gt;Type Name = TEXT&lt;br /&gt;Type Name = TINYTEXT&lt;br /&gt;Type Name = CHAR&lt;br /&gt;Type Name = NUMERIC&lt;br /&gt;Type Name = DECIMAL&lt;br /&gt;Type Name = INTEGER&lt;br /&gt;Type Name = INT&lt;br /&gt;Type Name = MEDIUMINT&lt;br /&gt;Type Name = SMALLINT&lt;br /&gt;Type Name = FLOAT&lt;br /&gt;Type Name = DOUBLE&lt;br /&gt;Type Name = DOUBLE PRECISION&lt;br /&gt;Type Name = REAL&lt;br /&gt;Type Name = VARCHAR&lt;br /&gt;Type Name = ENUM&lt;br /&gt;Type Name = SET&lt;br /&gt;Type Name = DATE&lt;br /&gt;Type Name = TIME&lt;br /&gt;Type Name = DATETIME&lt;br /&gt;Type Name = TIMESTAMP</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/8962127444135690768/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/8962127444135690768' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/8962127444135690768'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/8962127444135690768'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/11/get-data-types-supported-by-database.html' title='Get data types supported by database'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-6484208205329669833</id><published>2008-11-19T08:47:00.000+05:30</published><updated>2008-11-19T08:47:00.708+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>How do I know if database support batch update?</title><content type='html'>import java.sql.Connection;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.DatabaseMetaData;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt; &lt;br /&gt;public class SupportBatch {&lt;br /&gt;    private static final String DRIVER = &quot;com.mysql.jdbc.Driver&quot;;&lt;br /&gt;    private static final String URL = &quot;jdbc:mysql://localhost/kodejava&quot;;&lt;br /&gt;    private static final String USERNAME = &quot;root&quot;;&lt;br /&gt;    private static final String PASSWORD = &quot;&quot;;&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        Connection connection = null;&lt;br /&gt;        try {&lt;br /&gt;            Class.forName(DRIVER);&lt;br /&gt;            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);&lt;br /&gt;            DatabaseMetaData metadata = connection.getMetaData();&lt;br /&gt; &lt;br /&gt;            //&lt;br /&gt;            // Check to see if the database support batch updates&lt;br /&gt;            //&lt;br /&gt;            boolean isBatchingSupported = metadata.supportsBatchUpdates();&lt;br /&gt;            System.out.println(&quot;Batching Supported = &quot; + isBatchingSupported);&lt;br /&gt;        } catch (SQLException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } finally {&lt;br /&gt;            if (connection != null) {&lt;br /&gt;                connection.close();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/6484208205329669833/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/6484208205329669833' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/6484208205329669833'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/6484208205329669833'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/11/how-do-i-know-if-database-support-batch.html' title='How do I know if database support batch update?'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-8728034562136542148</id><published>2008-11-17T08:46:00.000+05:30</published><updated>2008-11-17T08:46:00.466+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>How do I know if database support scrollable result sets?</title><content type='html'>import java.sql.*;&lt;br /&gt; &lt;br /&gt;public class SupportScrollableResultSet {&lt;br /&gt;    private static final String DRIVER = &quot;com.mysql.jdbc.Driver&quot;;&lt;br /&gt;    private static final String URL = &quot;jdbc:mysql://localhost/kodejava&quot;;&lt;br /&gt;    private static final String USERNAME = &quot;root&quot;;&lt;br /&gt;    private static final String PASSWORD = &quot;&quot;;&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        Connection connection = null;&lt;br /&gt;        try {&lt;br /&gt;            Class.forName(DRIVER);&lt;br /&gt;            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);&lt;br /&gt;            DatabaseMetaData metadata = connection.getMetaData();&lt;br /&gt; &lt;br /&gt;            boolean supportForwardOnly =&lt;br /&gt;                    metadata.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY);&lt;br /&gt;            System.out.println(&quot;supportForwardOnly = &quot; + supportForwardOnly);&lt;br /&gt; &lt;br /&gt;            boolean supportScrollInsensitive =&lt;br /&gt;                    metadata.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE);&lt;br /&gt;            System.out.println(&quot;supportScrollInsensitive = &quot; + supportScrollInsensitive);&lt;br /&gt; &lt;br /&gt;            boolean supportScrollSensitive =&lt;br /&gt;                    metadata.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE);&lt;br /&gt;            System.out.println(&quot;supportScrollSensitive = &quot; + supportScrollSensitive);&lt;br /&gt;        } catch (SQLException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } finally {&lt;br /&gt;            if (connection != null) {&lt;br /&gt;                connection.close();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/8728034562136542148/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/8728034562136542148' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/8728034562136542148'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/8728034562136542148'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/11/how-do-i-know-if-database-support_17.html' title='How do I know if database support scrollable result sets?'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-6666394581476609021</id><published>2008-11-15T08:44:00.000+05:30</published><updated>2008-11-15T08:44:00.632+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>How do I know if database support updatable result sets?</title><content type='html'>import java.sql.*;&lt;br /&gt; &lt;br /&gt;public class SupportUpdatetableResultSet {&lt;br /&gt;    private static final String DRIVER = &quot;com.mysql.jdbc.Driver&quot;;&lt;br /&gt;    private static final String URL = &quot;jdbc:mysql://localhost/kodejava&quot;;&lt;br /&gt;    private static final String USERNAME = &quot;root&quot;;&lt;br /&gt;    private static final String PASSWORD = &quot;&quot;;&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        Connection connection = null;&lt;br /&gt;        try {&lt;br /&gt;            Class.forName(DRIVER);&lt;br /&gt;            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);&lt;br /&gt;            DatabaseMetaData metadata = connection.getMetaData();&lt;br /&gt; &lt;br /&gt;            boolean updatable = metadata.supportsResultSetConcurrency(&lt;br /&gt;                    ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);&lt;br /&gt; &lt;br /&gt;            System.out.println(&quot;Updatable ResultSet supported = &quot; + updatable);&lt;br /&gt;        } catch (SQLException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } finally {&lt;br /&gt;            if (connection != null) {&lt;br /&gt;                connection.close();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/6666394581476609021/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/6666394581476609021' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/6666394581476609021'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/6666394581476609021'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/11/how-do-i-know-if-database-support.html' title='How do I know if database support updatable result sets?'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-6400229902270723524</id><published>2008-11-13T08:40:00.001+05:30</published><updated>2008-11-13T08:40:00.250+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>Get database maximum table name length</title><content type='html'>import java.sql.Connection;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.DatabaseMetaData;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt; &lt;br /&gt;public class MaximumTableNameLength {&lt;br /&gt;    private static final String DRIVER = &quot;com.mysql.jdbc.Driver&quot;;&lt;br /&gt;    private static final String URL = &quot;jdbc:mysql://localhost/kodejava&quot;;&lt;br /&gt;    private static final String USERNAME = &quot;root&quot;;&lt;br /&gt;    private static final String PASSWORD = &quot;&quot;;&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        Connection connection = null;&lt;br /&gt;        try {&lt;br /&gt;            Class.forName(DRIVER);&lt;br /&gt;            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);&lt;br /&gt;            DatabaseMetaData metadata = connection.getMetaData();&lt;br /&gt; &lt;br /&gt;            //&lt;br /&gt;            // Get the information of maximum length of database table name&lt;br /&gt;            //&lt;br /&gt;            int maxLength = metadata.getMaxTableNameLength();&lt;br /&gt;            System.out.println(&quot;Max Table Name Length = &quot; + maxLength);&lt;br /&gt;        } catch (SQLException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } finally {&lt;br /&gt;            if (connection != null) {&lt;br /&gt;                connection.close();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/6400229902270723524/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/6400229902270723524' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/6400229902270723524'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/6400229902270723524'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/11/get-database-maximum-table-name-length.html' title='Get database maximum table name length'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-5322809885413403688</id><published>2008-11-11T08:38:00.000+05:30</published><updated>2008-11-11T08:38:00.587+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>Get the max concurrent connection to a database</title><content type='html'>import java.sql.Connection;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.DatabaseMetaData;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt; &lt;br /&gt;public class MaxConcurrentConnection {&lt;br /&gt;    private static final String DRIVER = &quot;com.mysql.jdbc.Driver&quot;;&lt;br /&gt;    private static final String URL = &quot;jdbc:mysql://localhost/kodejava&quot;;&lt;br /&gt;    private static final String USERNAME = &quot;root&quot;;&lt;br /&gt;    private static final String PASSWORD = &quot;&quot;;&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        Connection connection = null;&lt;br /&gt;        try {&lt;br /&gt;            Class.forName(DRIVER);&lt;br /&gt;            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);&lt;br /&gt;            DatabaseMetaData metadata = connection.getMetaData();&lt;br /&gt; &lt;br /&gt;            //&lt;br /&gt;            // Get the information of maximum concurrent connection to the&lt;br /&gt;            // database. The maximum number of active connections possible at&lt;br /&gt;            // one time; a result of zero means that there is no limit or the&lt;br /&gt;            // limit is not known&lt;br /&gt;            //&lt;br /&gt;            int maxConnection = metadata.getMaxConnections();&lt;br /&gt;            System.out.println(&quot;Maximum Connection = &quot; + maxConnection);&lt;br /&gt;        } catch (SQLException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } finally {&lt;br /&gt;            if (connection != null) {&lt;br /&gt;                connection.close();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/5322809885413403688/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/5322809885413403688' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/5322809885413403688'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/5322809885413403688'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/11/get-max-concurrent-connection-to.html' title='Get the max concurrent connection to a database'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-6208004158760223225</id><published>2008-11-09T08:35:00.000+05:30</published><updated>2008-11-09T08:35:00.759+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>Get string functions supported by database</title><content type='html'>import java.sql.Connection;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.DatabaseMetaData;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt; &lt;br /&gt;public class StringFunction {&lt;br /&gt;    private static final String DRIVER = &quot;com.mysql.jdbc.Driver&quot;;&lt;br /&gt;    private static final String URL = &quot;jdbc:mysql://localhost/kodejava&quot;;&lt;br /&gt;    private static final String USERNAME = &quot;root&quot;;&lt;br /&gt;    private static final String PASSWORD = &quot;&quot;;&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        Connection connection = null;&lt;br /&gt;        try {&lt;br /&gt;            Class.forName(DRIVER);&lt;br /&gt;            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);&lt;br /&gt;            DatabaseMetaData metadata = connection.getMetaData();&lt;br /&gt; &lt;br /&gt;            //&lt;br /&gt;            // Get string functions supported by database&lt;br /&gt;            //&lt;br /&gt;            String[] functions = metadata.getStringFunctions().split(&quot;,\\s*&quot;);&lt;br /&gt;            &lt;br /&gt;            for (int i = 0; i &lt; functions.length; i++) {&lt;br /&gt;                String function = functions[i];&lt;br /&gt;                System.out.println(&quot;Function = &quot; + function);&lt;br /&gt;            }&lt;br /&gt;        } catch (SQLException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } finally {&lt;br /&gt;            if (connection != null) {&lt;br /&gt;                connection.close();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt; Here is the result of string functions supported by MySQL database:&lt;br /&gt;&lt;br /&gt;Function = ASCII&lt;br /&gt;Function = BIN&lt;br /&gt;Function = BIT_LENGTH&lt;br /&gt;Function = CHAR&lt;br /&gt;Function = CHARACTER_LENGTH&lt;br /&gt;Function = CHAR_LENGTH&lt;br /&gt;Function = CONCAT&lt;br /&gt;Function = CONCAT_WS&lt;br /&gt;Function = CONV&lt;br /&gt;Function = ELT&lt;br /&gt;Function = EXPORT_SET&lt;br /&gt;Function = FIELD&lt;br /&gt;Function = FIND_IN_SET&lt;br /&gt;Function = HEX&lt;br /&gt;Function = INSERT&lt;br /&gt;Function = INSTR&lt;br /&gt;Function = LCASE&lt;br /&gt;Function = LEFT&lt;br /&gt;Function = LENGTH&lt;br /&gt;Function = LOAD_FILE&lt;br /&gt;Function = LOCATE&lt;br /&gt;Function = LOCATE&lt;br /&gt;Function = LOWER&lt;br /&gt;Function = LPAD&lt;br /&gt;Function = LTRIM&lt;br /&gt;Function = MAKE_SET&lt;br /&gt;Function = MATCH&lt;br /&gt;Function = MID&lt;br /&gt;Function = OCT&lt;br /&gt;Function = OCTET_LENGTH&lt;br /&gt;Function = ORD&lt;br /&gt;Function = POSITION&lt;br /&gt;Function = QUOTE&lt;br /&gt;Function = REPEAT&lt;br /&gt;Function = REPLACE&lt;br /&gt;Function = REVERSE&lt;br /&gt;Function = RIGHT&lt;br /&gt;Function = RPAD&lt;br /&gt;Function = RTRIM&lt;br /&gt;Function = SOUNDEX&lt;br /&gt;Function = SPACE&lt;br /&gt;Function = STRCMP&lt;br /&gt;Function = SUBSTRING&lt;br /&gt;Function = SUBSTRING&lt;br /&gt;Function = SUBSTRING&lt;br /&gt;Function = SUBSTRING&lt;br /&gt;Function = SUBSTRING_INDEX&lt;br /&gt;Function = TRIM&lt;br /&gt;Function = UCASE&lt;br /&gt;Function = UPPER</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/6208004158760223225/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/6208004158760223225' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/6208004158760223225'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/6208004158760223225'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/11/get-string-functions-supported-by.html' title='Get string functions supported by database'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-8385539418361921884</id><published>2008-11-07T08:31:00.000+05:30</published><updated>2008-11-07T08:31:00.434+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>Get numeric functions supported by database</title><content type='html'>import java.sql.Connection;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.DatabaseMetaData;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt; &lt;br /&gt;public class NumericFunction {&lt;br /&gt;    private static final String DRIVER = &quot;com.mysql.jdbc.Driver&quot;;&lt;br /&gt;    private static final String URL = &quot;jdbc:mysql://localhost/kodejava&quot;;&lt;br /&gt;    private static final String USERNAME = &quot;root&quot;;&lt;br /&gt;    private static final String PASSWORD = &quot;&quot;;&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        Connection connection = null;&lt;br /&gt;        try {&lt;br /&gt;            Class.forName(DRIVER);&lt;br /&gt;            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);&lt;br /&gt;            DatabaseMetaData metadata = connection.getMetaData();&lt;br /&gt; &lt;br /&gt;            //&lt;br /&gt;            // Get numeric functions supported by database&lt;br /&gt;            //&lt;br /&gt;            String[] functions = metadata.getNumericFunctions().split(&quot;,\\s*&quot;);&lt;br /&gt; &lt;br /&gt;            for (int i = 0; i &lt; functions.length; i++) {&lt;br /&gt;                String function = functions[i];&lt;br /&gt;                System.out.println(&quot;Function = &quot; + function);&lt;br /&gt;            }&lt;br /&gt;        } catch (SQLException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } finally {&lt;br /&gt;            if (connection != null) {&lt;br /&gt;                connection.close();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;Here is the numeric functions supported by MySQL database.&lt;br /&gt;&lt;br /&gt;Function = ABS&lt;br /&gt;Function = ACOS&lt;br /&gt;Function = ASIN&lt;br /&gt;Function = ATAN&lt;br /&gt;Function = ATAN2&lt;br /&gt;Function = BIT_COUNT&lt;br /&gt;Function = CEILING&lt;br /&gt;Function = COS&lt;br /&gt;Function = COT&lt;br /&gt;Function = DEGREES&lt;br /&gt;Function = EXP&lt;br /&gt;Function = FLOOR&lt;br /&gt;Function = LOG&lt;br /&gt;Function = LOG10&lt;br /&gt;Function = MAX&lt;br /&gt;Function = MIN&lt;br /&gt;Function = MOD&lt;br /&gt;Function = PI&lt;br /&gt;Function = POW&lt;br /&gt;Function = POWER&lt;br /&gt;Function = RADIANS&lt;br /&gt;Function = RAND&lt;br /&gt;Function = ROUND&lt;br /&gt;Function = SIN&lt;br /&gt;Function = SQRT&lt;br /&gt;Function = TAN&lt;br /&gt;Function = TRUNCATE</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/8385539418361921884/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/8385539418361921884' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/8385539418361921884'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/8385539418361921884'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/11/get-numeric-functions-supported-by.html' title='Get numeric functions supported by database'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-4031150285278180345</id><published>2008-11-05T08:29:00.000+05:30</published><updated>2008-11-05T08:29:00.395+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>Get date time functions supported by database</title><content type='html'>import java.sql.Connection;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.DatabaseMetaData;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt; &lt;br /&gt;public class DateTimeFunction {&lt;br /&gt;    private static final String DRIVER = &quot;com.mysql.jdbc.Driver&quot;;&lt;br /&gt;    private static final String URL = &quot;jdbc:mysql://localhost/kodejava&quot;;&lt;br /&gt;    private static final String USERNAME = &quot;root&quot;;&lt;br /&gt;    private static final String PASSWORD = &quot;&quot;;&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        Connection connection = null;&lt;br /&gt;        try {&lt;br /&gt;            Class.forName(DRIVER);&lt;br /&gt;            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);&lt;br /&gt;            DatabaseMetaData metadata = connection.getMetaData();&lt;br /&gt; &lt;br /&gt;            //&lt;br /&gt;            // Get date and time functions supported by database&lt;br /&gt;            //&lt;br /&gt;            String[] functions = metadata.getTimeDateFunctions().split(&quot;,\\s*&quot;);&lt;br /&gt; &lt;br /&gt;            for (int i = 0; i &lt; functions.length; i++) {&lt;br /&gt;                String function = functions[i];&lt;br /&gt;                System.out.println(&quot;Function = &quot; + function);&lt;br /&gt;            }&lt;br /&gt;        } catch (SQLException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } finally {&lt;br /&gt;            if (connection != null) {&lt;br /&gt;                connection.close();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Date and time functions supported by MySQL database.&lt;br /&gt;&lt;br /&gt;Function = DAYOFWEEK&lt;br /&gt;Function = WEEKDAY&lt;br /&gt;Function = DAYOFMONTH&lt;br /&gt;Function = DAYOFYEAR&lt;br /&gt;Function = MONTH&lt;br /&gt;Function = DAYNAME&lt;br /&gt;Function = MONTHNAME&lt;br /&gt;Function = QUARTER&lt;br /&gt;Function = WEEK&lt;br /&gt;Function = YEAR&lt;br /&gt;Function = HOUR&lt;br /&gt;Function = MINUTE&lt;br /&gt;Function = SECOND&lt;br /&gt;Function = PERIOD_ADD&lt;br /&gt;Function = PERIOD_DIFF&lt;br /&gt;Function = TO_DAYS&lt;br /&gt;Function = FROM_DAYS&lt;br /&gt;Function = DATE_FORMAT&lt;br /&gt;Function = TIME_FORMAT&lt;br /&gt;Function = CURDATE&lt;br /&gt;Function = CURRENT_DATE&lt;br /&gt;Function = CURTIME&lt;br /&gt;Function = CURRENT_TIME&lt;br /&gt;Function = NOW&lt;br /&gt;Function = SYSDATE&lt;br /&gt;Function = CURRENT_TIMESTAMP&lt;br /&gt;Function = UNIX_TIMESTAMP&lt;br /&gt;Function = FROM_UNIXTIME&lt;br /&gt;Function = SEC_TO_TIME&lt;br /&gt;Function = TIME_TO_SEC</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/4031150285278180345/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/4031150285278180345' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/4031150285278180345'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/4031150285278180345'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/11/get-date-time-functions-supported-by.html' title='Get date time functions supported by database'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-851073084745604613</id><published>2008-11-03T08:24:00.002+05:30</published><updated>2008-11-03T08:24:00.357+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.sql"/><title type='text'>Get system functions supported by database</title><content type='html'>import java.sql.Connection;&lt;br /&gt;import java.sql.DriverManager;&lt;br /&gt;import java.sql.DatabaseMetaData;&lt;br /&gt;import java.sql.SQLException;&lt;br /&gt; &lt;br /&gt;public class SystemFunction {&lt;br /&gt;    private static final String DRIVER = &quot;com.mysql.jdbc.Driver&quot;;&lt;br /&gt;    private static final String URL = &quot;jdbc:mysql://localhost/kodejava&quot;;&lt;br /&gt;    private static final String USERNAME = &quot;root&quot;;&lt;br /&gt;    private static final String PASSWORD = &quot;&quot;;&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        Connection connection = null;&lt;br /&gt;        try {&lt;br /&gt;            Class.forName(DRIVER);&lt;br /&gt;            connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);&lt;br /&gt;            DatabaseMetaData metadata = connection.getMetaData();&lt;br /&gt; &lt;br /&gt;            //&lt;br /&gt;            // Get system functions supported by database&lt;br /&gt;            //&lt;br /&gt;            String[] functions = metadata.getSystemFunctions().split(&quot;,\\s*&quot;);&lt;br /&gt; &lt;br /&gt;            for (int i = 0; i &lt; functions.length; i++) {&lt;br /&gt;                String function = functions[i];&lt;br /&gt;                System.out.println(&quot;Function = &quot; + function);&lt;br /&gt;            }&lt;br /&gt;        } catch (SQLException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        } finally {&lt;br /&gt;            if (connection != null) {&lt;br /&gt;                connection.close();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here are MySQL database supported system functions.&lt;br /&gt;&lt;br /&gt;Function = DATABASE&lt;br /&gt;Function = USER&lt;br /&gt;Function = SYSTEM_USER&lt;br /&gt;Function = SESSION_USER&lt;br /&gt;Function = PASSWORD&lt;br /&gt;Function = ENCRYPT&lt;br /&gt;Function = LAST_INSERT_ID&lt;br /&gt;Function = VERSION</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/851073084745604613/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/851073084745604613' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/851073084745604613'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/851073084745604613'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/11/get-system-functions-supported-by.html' title='Get system functions supported by database'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-3483343285160374595</id><published>2008-11-01T08:22:00.001+05:30</published><updated>2008-11-01T08:22:00.268+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.math"/><title type='text'>Math operation for BigInteger</title><content type='html'>import java.math.BigInteger;&lt;br /&gt; &lt;br /&gt;public class BigIntegerOperation {&lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;        BigInteger numberA = new BigInteger(&quot;98765432123456789&quot;);&lt;br /&gt;        BigInteger numberB = BigInteger.TEN;&lt;br /&gt; &lt;br /&gt;        numberA = numberA.add(numberB);&lt;br /&gt;        System.out.println(&quot;numberA = &quot; + numberA);&lt;br /&gt; &lt;br /&gt;        numberA = numberA.multiply(numberB);&lt;br /&gt;        System.out.println(&quot;numberA = &quot; + numberA);&lt;br /&gt; &lt;br /&gt;        numberA = numberA.subtract(numberB);&lt;br /&gt;        System.out.println(&quot;numberA = &quot; + numberA);&lt;br /&gt; &lt;br /&gt;        numberA = numberA.divide(numberB);&lt;br /&gt;        System.out.println(&quot;numberA = &quot; + numberA);&lt;br /&gt; &lt;br /&gt;        numberA = numberA.mod(numberB);&lt;br /&gt;        System.out.println(&quot;numberA = &quot; + numberA);&lt;br /&gt; &lt;br /&gt;        numberA = numberA.pow(2);&lt;br /&gt;        System.out.println(&quot;numberA = &quot; + numberA);&lt;br /&gt; &lt;br /&gt;        numberA = numberA.negate();&lt;br /&gt;        System.out.println(&quot;numberA = &quot; + numberA);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Our class result are:&lt;br /&gt;&lt;br /&gt;numberA = 98765432123456799&lt;br /&gt;numberA = 987654321234567990&lt;br /&gt;numberA = 987654321234567980&lt;br /&gt;numberA = 98765432123456798&lt;br /&gt;numberA = 8&lt;br /&gt;numberA = 64&lt;br /&gt;numberA = -64</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/3483343285160374595/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/3483343285160374595' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/3483343285160374595'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/3483343285160374595'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/11/math-operation-for-biginteger.html' title='Math operation for BigInteger'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-7761328066130508128</id><published>2008-10-31T08:06:00.001+05:30</published><updated>2008-10-31T08:06:00.578+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.math"/><title type='text'>Convert BigInteger into another radix number</title><content type='html'>In this example you&#39;ll see how we can convert a BigInteger number into another radix such as binary, octal and hexadecimal.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.math.BigInteger;&lt;br /&gt; &lt;br /&gt;public class BigIntegerConversion {&lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;        BigInteger number = new BigInteger(&quot;2008&quot;);&lt;br /&gt; &lt;br /&gt;        System.out.println(&quot;Number      = &quot; + number);&lt;br /&gt;        System.out.println(&quot;Binary      = &quot; + number.toString(2));&lt;br /&gt;        System.out.println(&quot;Octal       = &quot; + number.toString(8));&lt;br /&gt;        System.out.println(&quot;Hexadecimal = &quot; + number.toString(16));&lt;br /&gt; &lt;br /&gt;        number = new BigInteger(&quot;FF&quot;, 16);&lt;br /&gt;        System.out.println(&quot;Number      = &quot; + number);&lt;br /&gt;        System.out.println(&quot;Number      = &quot; + number.toString(16));&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The result of our examples:&lt;br /&gt;&lt;br /&gt;Number      = 2008&lt;br /&gt;Binary      = 11111011000&lt;br /&gt;Octal       = 3730&lt;br /&gt;Hexadecimal = 7d8&lt;br /&gt;Number      = 255&lt;br /&gt;Number      = ff</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/7761328066130508128/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/7761328066130508128' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/7761328066130508128'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/7761328066130508128'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/10/convert-biginteger-into-another-radix.html' title='Convert BigInteger into another radix number'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-1459509338897582733</id><published>2008-10-29T08:10:00.000+05:30</published><updated>2008-10-29T08:10:00.832+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.math"/><title type='text'>Math operation for BigDecimal</title><content type='html'>import java.math.BigDecimal;&lt;br /&gt; &lt;br /&gt;public class BigDecimalOperation {&lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;        BigDecimal decimalA = new BigDecimal(&quot;98765432123456789&quot;);&lt;br /&gt;        BigDecimal decimalB = new BigDecimal(&quot;10&quot;);&lt;br /&gt; &lt;br /&gt;        decimalA = decimalA.add(decimalB);&lt;br /&gt;        System.out.println(&quot;decimalA = &quot; + decimalA);&lt;br /&gt; &lt;br /&gt;        decimalA = decimalA.multiply(decimalB);&lt;br /&gt;        System.out.println(&quot;decimalA = &quot; + decimalA);&lt;br /&gt; &lt;br /&gt;        decimalA = decimalA.subtract(decimalB);&lt;br /&gt;        System.out.println(&quot;decimalA = &quot; + decimalA);&lt;br /&gt; &lt;br /&gt;        decimalA = decimalA.divide(decimalB);&lt;br /&gt;        System.out.println(&quot;decimalA = &quot; + decimalA);&lt;br /&gt; &lt;br /&gt;        decimalA = decimalA.pow(2);&lt;br /&gt;        System.out.println(&quot;decimalA = &quot; + decimalA);&lt;br /&gt; &lt;br /&gt;        decimalA = decimalA.negate();&lt;br /&gt;        System.out.println(&quot;decimalA = &quot; + decimalA);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;Our class result are:&lt;br /&gt;&lt;br /&gt;decimalA = 98765432123456799&lt;br /&gt;decimalA = 987654321234567990&lt;br /&gt;decimalA = 987654321234567980&lt;br /&gt;decimalA = 98765432123456798&lt;br /&gt;decimalA = 9754610582533151990855052972412804&lt;br /&gt;decimalA = -9754610582533151990855052972412804</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/1459509338897582733/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/1459509338897582733' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/1459509338897582733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/1459509338897582733'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/10/math-operation-for-bigdecimal.html' title='Math operation for BigDecimal'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-7411317930261573225</id><published>2008-10-27T08:01:00.001+05:30</published><updated>2008-10-27T08:01:00.163+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.beans"/><title type='text'>Convert a bean to XML persistence</title><content type='html'>import java.beans.XMLEncoder;&lt;br /&gt;import java.io.BufferedOutputStream;&lt;br /&gt;import java.io.FileOutputStream;&lt;br /&gt;import java.io.FileNotFoundException;&lt;br /&gt; &lt;br /&gt;public class BeanToXML {&lt;br /&gt;    private Long id;&lt;br /&gt;    private String itemName;&lt;br /&gt;    private String itemColour;&lt;br /&gt;    private Integer itemQuantities;&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;        BeanToXML bean = new BeanToXML();&lt;br /&gt;        bean.setId(new Long(1));&lt;br /&gt;        bean.setItemName(&quot;T-Shirt&quot;);&lt;br /&gt;        bean.setItemColour(&quot;Dark Red&quot;);&lt;br /&gt;        bean.setItemQuantities(new Integer(100));&lt;br /&gt;        &lt;br /&gt;        try {&lt;br /&gt;            XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(&lt;br /&gt;                    new FileOutputStream(&quot;Bean.xml&quot;)));&lt;br /&gt; &lt;br /&gt;            //&lt;br /&gt;            // Write an XML representation of the specified object to the output.&lt;br /&gt;            //&lt;br /&gt;            encoder.writeObject(bean);&lt;br /&gt;            encoder.close();&lt;br /&gt;        } catch (FileNotFoundException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public Long getId() {&lt;br /&gt;        return id;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public void setId(Long id) {&lt;br /&gt;        this.id = id;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public String getItemName() {&lt;br /&gt;        return itemName;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public void setItemName(String itemName) {&lt;br /&gt;        this.itemName = itemName;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public String getItemColour() {&lt;br /&gt;        return itemColour;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public void setItemColour(String itemColour) {&lt;br /&gt;        this.itemColour = itemColour;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public Integer getItemQuantities() {&lt;br /&gt;        return itemQuantities;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public void setItemQuantities(Integer itemQuantities) {&lt;br /&gt;        this.itemQuantities = itemQuantities;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The XML persistence will be like:&lt;br /&gt;&lt;br /&gt;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;br /&gt;&lt;java version=&quot;1.6.0_02&quot; class=&quot;java.beans.XMLDecoder&quot;&gt; &lt;br /&gt; &lt;object class=&quot;org.kodejava.example.bean.BeanToXML&quot;&gt; &lt;br /&gt;  &lt;void property=&quot;id&quot;&gt; &lt;br /&gt;   &lt;long&gt;1&lt;/long&gt; &lt;br /&gt;  &lt;/void&gt; &lt;br /&gt;  &lt;void property=&quot;itemColour&quot;&gt; &lt;br /&gt;   &lt;string&gt;Dark Red&lt;/string&gt; &lt;br /&gt;  &lt;/void&gt; &lt;br /&gt;  &lt;void property=&quot;itemName&quot;&gt; &lt;br /&gt;   &lt;string&gt;T-Shirt&lt;/string&gt; &lt;br /&gt;  &lt;/void&gt; &lt;br /&gt;  &lt;void property=&quot;itemQuantities&quot;&gt; &lt;br /&gt;   &lt;int&gt;100&lt;/int&gt; &lt;br /&gt;  &lt;/void&gt; &lt;br /&gt; &lt;/object&gt; &lt;br /&gt;&lt;/java&gt;</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/7411317930261573225/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/7411317930261573225' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/7411317930261573225'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/7411317930261573225'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/10/convert-bean-to-xml-persistence.html' title='Convert a bean to XML persistence'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-2954763128530144497</id><published>2008-10-25T08:00:00.000+05:30</published><updated>2008-10-25T08:00:00.366+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.beans"/><title type='text'>Convert an XML persistence to bean</title><content type='html'>import java.beans.XMLDecoder;&lt;br /&gt;import java.io.BufferedInputStream;&lt;br /&gt;import java.io.FileInputStream;&lt;br /&gt;import java.io.FileNotFoundException;&lt;br /&gt; &lt;br /&gt;public class XmlToBean {&lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;        try {&lt;br /&gt;            XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(&lt;br /&gt;                    new FileInputStream(&quot;Bean.xml&quot;)));&lt;br /&gt; &lt;br /&gt;            //&lt;br /&gt;            // Reads the next object from the underlying input stream.&lt;br /&gt;            //&lt;br /&gt;            BeanToXML bean = (BeanToXML) decoder.readObject();&lt;br /&gt;            decoder.close();&lt;br /&gt; &lt;br /&gt;            System.out.println(&quot;ID              = &quot; + bean.getId());&lt;br /&gt;            System.out.println(&quot;Item Name       = &quot; + bean.getItemName());&lt;br /&gt;            System.out.println(&quot;Item Colour     = &quot; + bean.getItemColour());&lt;br /&gt;            System.out.println(&quot;Item Quantities = &quot; + bean.getItemQuantities());&lt;br /&gt;        } catch (FileNotFoundException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The result are:&lt;br /&gt;&lt;br /&gt;ID              = 1&lt;br /&gt;Item Name       = T-Shirt&lt;br /&gt;Item Colour     = Dark Red&lt;br /&gt;Item Quantities = 100</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/2954763128530144497/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/2954763128530144497' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/2954763128530144497'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/2954763128530144497'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/10/convert-xml-persistence-to-bean.html' title='Convert an XML persistence to bean'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2837485492691527529.post-815867604511036324</id><published>2008-10-23T07:57:00.000+05:30</published><updated>2008-10-23T07:57:00.488+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="java.beans"/><title type='text'>Prevent bean&#39;s property being serialized to XML</title><content type='html'>import java.beans.*;&lt;br /&gt;import java.io.BufferedOutputStream;&lt;br /&gt;import java.io.FileOutputStream;&lt;br /&gt;import java.io.FileNotFoundException;&lt;br /&gt; &lt;br /&gt;public class BeanToXmlTransient {&lt;br /&gt;    private Long id;&lt;br /&gt;    private String itemName;&lt;br /&gt;    private String itemColour;&lt;br /&gt;    private Integer itemQuantities;&lt;br /&gt; &lt;br /&gt;    static {&lt;br /&gt;        try {&lt;br /&gt;            //&lt;br /&gt;            // In this block will change the attribute type of the itemQuantities&lt;br /&gt;            // to transient so it will be not serialized to xml when we use&lt;br /&gt;            // XMLEncode to convert the bean to xml persistence.&lt;br /&gt;            //&lt;br /&gt;            BeanInfo bi = Introspector.getBeanInfo(BeanToXmlTransient.class);&lt;br /&gt;            PropertyDescriptor[] pds = bi.getPropertyDescriptors();&lt;br /&gt;            for (int i = 0; i &lt; pds.length; i++) {&lt;br /&gt;                PropertyDescriptor propertyDescriptor = pds[i];&lt;br /&gt;                if (propertyDescriptor.getName().equals(&quot;itemQuantities&quot;)) {&lt;br /&gt;                    propertyDescriptor.setValue(&quot;transient&quot;, Boolean.TRUE);&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        } catch (IntrospectionException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;        BeanToXmlTransient bean = new BeanToXmlTransient();&lt;br /&gt;        bean.setId(new Long(1));&lt;br /&gt;        bean.setItemName(&quot;T-Shirt&quot;);&lt;br /&gt;        bean.setItemColour(&quot;Dark Red&quot;);&lt;br /&gt;        bean.setItemQuantities(new Integer(100));&lt;br /&gt; &lt;br /&gt;        try {&lt;br /&gt;            XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(&lt;br /&gt;                    new FileOutputStream(&quot;BeanTransient.xml&quot;)));&lt;br /&gt; &lt;br /&gt;            //&lt;br /&gt;            // Write an XML representation of the specified object to the output.&lt;br /&gt;            //&lt;br /&gt;            encoder.writeObject(bean);&lt;br /&gt;            encoder.close();&lt;br /&gt;        } catch (FileNotFoundException e) {&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public Long getId() {&lt;br /&gt;        return id;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public void setId(Long id) {&lt;br /&gt;        this.id = id;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public String getItemName() {&lt;br /&gt;        return itemName;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public void setItemName(String itemName) {&lt;br /&gt;        this.itemName = itemName;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public String getItemColour() {&lt;br /&gt;        return itemColour;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public void setItemColour(String itemColour) {&lt;br /&gt;        this.itemColour = itemColour;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public Integer getItemQuantities() {&lt;br /&gt;        return itemQuantities;&lt;br /&gt;    }&lt;br /&gt; &lt;br /&gt;    public void setItemQuantities(Integer itemQuantities) {&lt;br /&gt;        this.itemQuantities = itemQuantities;&lt;br /&gt;    }&lt;br /&gt;}</content><link rel='replies' type='application/atom+xml' href='http://java-mani.blogspot.com/feeds/815867604511036324/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2837485492691527529/815867604511036324' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/815867604511036324'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2837485492691527529/posts/default/815867604511036324'/><link rel='alternate' type='text/html' href='http://java-mani.blogspot.com/2008/10/prevent-beans-property-being-serialized.html' title='Prevent bean&#39;s property being serialized to XML'/><author><name>JAVA</name><uri>http://www.blogger.com/profile/02104538212466928023</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>