cURL Error: 0{"id":26,"date":"2010-10-19T14:01:03","date_gmt":"2010-10-19T14:01:03","guid":{"rendered":"http:\/\/javamylove.wordpress.com\/?p=26"},"modified":"2026-09-22T15:24:05","modified_gmt":"2026-09-22T15:24:05","slug":"javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue","status":"publish","type":"post","link":"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/","title":{"rendered":"javax.imageio.ImageIO and JTDS JDBC Driver to the Rescue"},"content":{"rendered":"<p>A friend of mine back home in Nigeria, a VB developer hollered at me sometimes last month to ask how he can retrieve blob data containing images stored in a MS SQL database and save them to the local disk. The database contains over 6,000 records. I&#8217;m sure there is a way to achieve this in VB, apparently he does not know. . . I completed the task in minutes. . .<\/p>\n<p>It&#8217;s been a long time I worked with MSSQL and I think I only used it once since I graduated from school in 2003. Don&#8217;t ask me why, ask MySQL. . .lol<\/p>\n<p>First, I don&#8217;t have MSSQL installed on my laptop which means I have to write a database independent code which should work for both MySQL and MSSQL. .<\/p>\n<p>I quickly setup a database, created a table and populated it some of my pictures. At the end, I had 30 records in my table. First, we run our select query. .<\/p>\n<p>[code]<\/p>\n<p>\/\/To store the image ID<br \/>\nString imageID;<\/p>\n<p>\/\/ To store the binary stream retrieved from the database<br \/>\nInputStream in;<\/p>\n<p>\/\/Path to save Image on local disk<br \/>\nString imagePath=&#8221;c:\\pictures\\&#8221;;<br \/>\nFile file;<\/p>\n<p>\/\/Will be used to store the image;<br \/>\nImageIcon icon;<br \/>\nImage image;<\/p>\n<p>PreparedStatement st=cn.prepareStatement(&#8220;select ImageID, BlobImage from tblImages&#8221;);<br \/>\nResultSet rs=st.executQuery();<br \/>\nwhile(rs.next())<br \/>\n{<br \/>\nimageID=rs.getString(1);<br \/>\nin=rs.getBinaryStream(2);<\/p>\n<p>\/\/Store the retrieved image ina byte array<br \/>\nbyte[] b= new byte[1024];<\/p>\n<p>\/\/Store the bytes in java.awt.Image object<br \/>\nimage=Toolkit.getDefaultToolkit().createImage(b);<\/p>\n<p>\/\/Convert java.awt.Image to javax.swing.ImageIcon;<\/p>\n<p>icon= new Imageicon(image);<\/p>\n<p>\/\/Convert the java.awt.Image to a BufferedImage<br \/>\nBufferedImage bi= new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);<br \/>\nGraphics2d g2d= bi.createGraphics(icon.getImage(),0,0,null);<\/p>\n<p>\/\/Create the file name. Our encoding is JPEG<br \/>\nimageName= imageID+&#8221;.jpg&#8221;;<br \/>\nfile= new File(imagePath+imageName);<\/p>\n<p>\/\/Now lets write out the image to our file path<br \/>\nImageIO.write(bi, &#8220;jpg&#8221;, file);<\/p>\n<p>}<\/p>\n<p>[\/code]<\/p>\n<p>This worked perfectly well with mySQL but there was a problem when he used it with MS SQL. He complained that only one image is retrieved and saved, and then the ResultSet closes. I figured out that the relationship between JDBC and MSSQL is not a rosy one. I tried JTDS driver, repackaged the application and sent to him. It worked perfect and retrieved the 6000 images in the database in 25 minutes but there was another problem. he could not log in to MSSQL with windows authentication. I sent him a dll file that was shipped with the JTDS package to paste in c:\\wondows\\system32 and that fixed it.<\/p>\n<p>Below is the UI<br \/>\n<img decoding=\"async\" src=\"http:\/\/www1.picturepush.com\/photo\/a\/4384999\/480\/Picture-Box\/bosun.jpg?v0\" alt=\"Screenshot\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A friend of mine back home in Nigeria, a VB developer hollered at me sometimes last month to ask how he can retrieve blob data containing images stored in a MS SQL database and save them to the local disk. The database contains over 6,000 records. I&#8217;m sure there is a way to achieve this in VB, apparently he does not know. . . I completed the task in minutes. . . It&#8217;s been a long time I worked with&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":9,"footnotes":""},"categories":[6],"tags":[16,17,21,25,29],"class_list":["post-26","post","type-post","status-publish","format-standard","hentry","category-java","tag-image-processing","tag-imageio","tag-jtds-jdbc","tag-mssql","tag-swing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>javax.imageio.ImageIO and JTDS JDBC Driver to the Rescue - Lukman<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"javax.imageio.ImageIO and JTDS JDBC Driver to the Rescue - Lukman\" \/>\n<meta property=\"og:description\" content=\"A friend of mine back home in Nigeria, a VB developer hollered at me sometimes last month to ask how he can retrieve blob data containing images stored in a MS SQL database and save them to the local disk. The database contains over 6,000 records. I&#8217;m sure there is a way to achieve this in VB, apparently he does not know. . . I completed the task in minutes. . . It&#8217;s been a long time I worked with&hellip;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/\" \/>\n<meta property=\"og:site_name\" content=\"Lukman\" \/>\n<meta property=\"article:published_time\" content=\"2010-10-19T14:01:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-09-22T15:24:05+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www1.picturepush.com\/photo\/a\/4384999\/480\/Picture-Box\/bosun.jpg?v0\" \/>\n<meta name=\"author\" content=\"Lukman\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Lukman\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/\"},\"author\":{\"name\":\"Lukman\",\"@id\":\"https:\/\/lukmanjaji.com\/#\/schema\/person\/78a62e6239894a2171dba402227b0b96\"},\"headline\":\"javax.imageio.ImageIO and JTDS JDBC Driver to the Rescue\",\"datePublished\":\"2010-10-19T14:01:03+00:00\",\"dateModified\":\"2026-09-22T15:24:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/\"},\"wordCount\":441,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/lukmanjaji.com\/#\/schema\/person\/78a62e6239894a2171dba402227b0b96\"},\"image\":{\"@id\":\"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www1.picturepush.com\/photo\/a\/4384999\/480\/Picture-Box\/bosun.jpg?v0\",\"keywords\":[\"image processing\",\"imageio\",\"jtds jdbc\",\"mssql\",\"Swing\"],\"articleSection\":[\"Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/\",\"url\":\"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/\",\"name\":\"javax.imageio.ImageIO and JTDS JDBC Driver to the Rescue - Lukman\",\"isPartOf\":{\"@id\":\"https:\/\/lukmanjaji.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/www1.picturepush.com\/photo\/a\/4384999\/480\/Picture-Box\/bosun.jpg?v0\",\"datePublished\":\"2010-10-19T14:01:03+00:00\",\"dateModified\":\"2026-09-22T15:24:05+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/#primaryimage\",\"url\":\"http:\/\/www1.picturepush.com\/photo\/a\/4384999\/480\/Picture-Box\/bosun.jpg?v0\",\"contentUrl\":\"http:\/\/www1.picturepush.com\/photo\/a\/4384999\/480\/Picture-Box\/bosun.jpg?v0\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/lukmanjaji.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"javax.imageio.ImageIO and JTDS JDBC Driver to the Rescue\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/lukmanjaji.com\/#website\",\"url\":\"https:\/\/lukmanjaji.com\/\",\"name\":\"Lukman\",\"description\":\"Me in 4 Nutshells\",\"publisher\":{\"@id\":\"https:\/\/lukmanjaji.com\/#\/schema\/person\/78a62e6239894a2171dba402227b0b96\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/lukmanjaji.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/lukmanjaji.com\/#\/schema\/person\/78a62e6239894a2171dba402227b0b96\",\"name\":\"Lukman\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/lukmanjaji.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a75f8a1133dbd0d25f80c79109b6dfd3179059c5ae0109ca2bcc3aa05c714642?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a75f8a1133dbd0d25f80c79109b6dfd3179059c5ae0109ca2bcc3aa05c714642?s=96&d=mm&r=g\",\"caption\":\"Lukman\"},\"logo\":{\"@id\":\"https:\/\/lukmanjaji.com\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/lukmanjaji.com\"],\"url\":\"https:\/\/lukmanjaji.com\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"javax.imageio.ImageIO and JTDS JDBC Driver to the Rescue - Lukman","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/","og_locale":"en_US","og_type":"article","og_title":"javax.imageio.ImageIO and JTDS JDBC Driver to the Rescue - Lukman","og_description":"A friend of mine back home in Nigeria, a VB developer hollered at me sometimes last month to ask how he can retrieve blob data containing images stored in a MS SQL database and save them to the local disk. The database contains over 6,000 records. I&#8217;m sure there is a way to achieve this in VB, apparently he does not know. . . I completed the task in minutes. . . It&#8217;s been a long time I worked with&hellip;","og_url":"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/","og_site_name":"Lukman","article_published_time":"2010-10-19T14:01:03+00:00","article_modified_time":"2026-09-22T15:24:05+00:00","og_image":[{"url":"http:\/\/www1.picturepush.com\/photo\/a\/4384999\/480\/Picture-Box\/bosun.jpg?v0","type":"","width":"","height":""}],"author":"Lukman","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Lukman","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/#article","isPartOf":{"@id":"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/"},"author":{"name":"Lukman","@id":"https:\/\/lukmanjaji.com\/#\/schema\/person\/78a62e6239894a2171dba402227b0b96"},"headline":"javax.imageio.ImageIO and JTDS JDBC Driver to the Rescue","datePublished":"2010-10-19T14:01:03+00:00","dateModified":"2026-09-22T15:24:05+00:00","mainEntityOfPage":{"@id":"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/"},"wordCount":441,"commentCount":1,"publisher":{"@id":"https:\/\/lukmanjaji.com\/#\/schema\/person\/78a62e6239894a2171dba402227b0b96"},"image":{"@id":"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/#primaryimage"},"thumbnailUrl":"http:\/\/www1.picturepush.com\/photo\/a\/4384999\/480\/Picture-Box\/bosun.jpg?v0","keywords":["image processing","imageio","jtds jdbc","mssql","Swing"],"articleSection":["Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/","url":"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/","name":"javax.imageio.ImageIO and JTDS JDBC Driver to the Rescue - Lukman","isPartOf":{"@id":"https:\/\/lukmanjaji.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/#primaryimage"},"image":{"@id":"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/#primaryimage"},"thumbnailUrl":"http:\/\/www1.picturepush.com\/photo\/a\/4384999\/480\/Picture-Box\/bosun.jpg?v0","datePublished":"2010-10-19T14:01:03+00:00","dateModified":"2026-09-22T15:24:05+00:00","breadcrumb":{"@id":"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/#primaryimage","url":"http:\/\/www1.picturepush.com\/photo\/a\/4384999\/480\/Picture-Box\/bosun.jpg?v0","contentUrl":"http:\/\/www1.picturepush.com\/photo\/a\/4384999\/480\/Picture-Box\/bosun.jpg?v0"},{"@type":"BreadcrumbList","@id":"https:\/\/lukmanjaji.com\/2010\/10\/19\/javax-imageio-imageio-and-jtds-jdbc-driver-to-the-rescue\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/lukmanjaji.com\/"},{"@type":"ListItem","position":2,"name":"javax.imageio.ImageIO and JTDS JDBC Driver to the Rescue"}]},{"@type":"WebSite","@id":"https:\/\/lukmanjaji.com\/#website","url":"https:\/\/lukmanjaji.com\/","name":"Lukman","description":"Me in 4 Nutshells","publisher":{"@id":"https:\/\/lukmanjaji.com\/#\/schema\/person\/78a62e6239894a2171dba402227b0b96"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/lukmanjaji.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/lukmanjaji.com\/#\/schema\/person\/78a62e6239894a2171dba402227b0b96","name":"Lukman","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/lukmanjaji.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a75f8a1133dbd0d25f80c79109b6dfd3179059c5ae0109ca2bcc3aa05c714642?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a75f8a1133dbd0d25f80c79109b6dfd3179059c5ae0109ca2bcc3aa05c714642?s=96&d=mm&r=g","caption":"Lukman"},"logo":{"@id":"https:\/\/lukmanjaji.com\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/lukmanjaji.com"],"url":"https:\/\/lukmanjaji.com\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/lukmanjaji.com\/wp-json\/wp\/v2\/posts\/26","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lukmanjaji.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lukmanjaji.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lukmanjaji.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lukmanjaji.com\/wp-json\/wp\/v2\/comments?post=26"}],"version-history":[{"count":4,"href":"https:\/\/lukmanjaji.com\/wp-json\/wp\/v2\/posts\/26\/revisions"}],"predecessor-version":[{"id":619,"href":"https:\/\/lukmanjaji.com\/wp-json\/wp\/v2\/posts\/26\/revisions\/619"}],"wp:attachment":[{"href":"https:\/\/lukmanjaji.com\/wp-json\/wp\/v2\/media?parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lukmanjaji.com\/wp-json\/wp\/v2\/categories?post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lukmanjaji.com\/wp-json\/wp\/v2\/tags?post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}