Oct 14 Moving Data From an Embedded Database to Oracle
Many enterprise software applications require a relational database. For test or evaluation purposes, or in entry-level configurations, many developers like to provide a database.  Typical candidates for embedding are Derby (previously IBM's Cloudscape, now part of the Apache project ), MySQL, or the free versions of Oracle, SQL Server or DB2. Providing a database makes it much easier for the vendor to get their applications up and running with minimal complications. However, while providing a database in certain configurations does solve many problems, it can cause others. After investing much time, energy, and money in getting a system up and running on this embedded, what if the customer decides to proceed, but wants to use their IT-blessed brand of database? Having a simple, database-independent way of migrating the data from the embedded database to one of the traditional enterprise brands would greatly simplify an ISV's implementation strategies. What if you could easily migrate the data from the embedded database to the leading enterprise databases? Without complicated vendor-specific load utilities? A few simple lines of java code, along with Progress DataDirect's Connect for JDBC drivers and you can do just that! Consider the case of an application vendor who has chosen to incorporate the Derby database into the demonstration version of their product. After many weeks or months, a successful implementation of their software is up and running at a customer. A great deal of data is now stored in the embedded Derby database, which is working fine. The good news is that the customer wants to buy! But the challenge is that the customer needs to have all of the data in the Derby database moved to Oracle. Traditionally, vendors would have faced a variety of strategies for extracting large amounts of data from one given database and inserting into another. Depending upon the brand of the target database, different tools might be used. Oracle has something called SQL*Loader to move large amounts of data into Oracle. SQL*Loader runs on many different platforms. Microsoft SQL Server has a similar tool, BCP, the Bulk Copy utility. BCP is a Windows-specific application. Sybase has it's own version of BCP, not surprising, given the common heritage between Sybase and SQL Server. All different, all standalone utilities, not things that can be readily incorporated into an application. ISVs may choose to write java or C code that attacks this in a more standard fashion, but then they lose the benefits of the bulk protocols that the previously mentioned tools provide. These bulk protocols can dramatically reduce the time it takes to load large volumes of data. Progress Datadirect's Connect products provide the best of both worlds, supporting these database-specific bulk protocols, but under industry-standard APIs such as ODBC, JDBC, and ADO.NET . Back to the ISV with the embedded Derby database who needs to move the Derby data to Oracle. Figure 1 shows a JDBC query of a Derby table named “Cities”.  Nothing unusual. Figure 2 shows an empty Oracle table with the same name and column definitions as the CITIES table in Derby. The target table must be defined prior to starting the actual load process. How to actually move the data from the Derby table to Oracle? See the simple java program shown in the Eclipse window in Figure 3. The application is extremely easy to understand. As detailed in the inline comments: 1. Establish a connection to the target Oracle database using Progress DataDirect's Connect for JDBC driver for Oracle. Standard URL defining the connection. Server address, the Oracle service name, user and password. 2.  Establish a connection to the source Derby database using the JDBC driver included with Derby. It happens to be running on the local machine. 3.  A statement object is created against the target Derby database. 4.  A resultset is created by the execution of the SELECT statement against the Derby table, CITIES. Steps 1-4 is standard JDBC code. Nothing unusual, nothing unique. Now for the “secret sauce” ! 5.  A DDBulkLoad object is what is used to communicate with the target Oracle database using Oracle's bulk protocols behind the scenes. If this were a DB2 or SQL Server or Sybase database, we'd use the EXACT SAME CODE here, but the DDBulkLoad object would be invoking that vendor's protocols for loading large volumes of data transparently to the programmer! Database-independent bulk loading! 6.  The bulkload object has to know which Oracle table is to be the target of this load operation. While in this case it happens to have the same name as the table in Derby, it does not have to. 7.  Load the resultset from the previous Derby query into the CITIES table in Oracle using the bulkload object! THAT IS IT! Figure 4 shows the CITIES table in Oracle, now fully populated! Game, Set, Match! This is how simple it is to code a database-independent data migration application that moves data from Derby to Oracle! You don't use Derby for your embedded database? Doesn't matter! If you can connect to it via JDBC and create a resultset, you're set. Is the target database something other than Oracle? This same strategy will work for moving data into DB2, SQL Server or Sybase! A truly database-agnostic, high-speed migration capability! //
Sep 4 The Evolution and Future of JDBC In the Enterprise
I recently sat down with the guys over at DZone to talk about what’s been going on in JDBC, and what lies in store for the future as well as the plans to get there. Talking about the future of technologies is always fun, but JDBC? I’m sure you all know that JDBC has been somewhat relegated to the back burner with all the persistence and architectural frameworks that are around, but all of them rely on good ol’ JDBC underneath to get the heavy lifting done – so the future of JDBC is important for anyone using these frameworks! So, head on over to DZone and see the interview yourself and see what’s in store for JDBC, Java, and the future of data access! http://java.dzone.com/videos/jesse-davis-jdbc-data -J
Aug 7 Easily Move Large Amounts of data with Bulk Load!
Many companies today are moving mountains of data – some are moving them into data warehouses to run reports, moving for duplication/archival, and more often than not, the design of these systems is accidental. Traditionally there has been no standards based way for moving these large amounts of data between systems, resulting in poorly architected solutions that suffer when additional systems come online or additional databases are thrown into the mix. We have now brought this technology into the ODBC, JDBC, and ADO.NET space, unlocking a standards based bulk loading mechanism that will outperform the vendor provided bulk loading tools, allowing you to easily and quickly move large amounts of data into data warehouses and other systems in a way that will grow with your company’s needs! We have recently recorded a webinar that covers real world scenarios and showcases a demonstration of our Bulk Loading in action using both our JDBC and ODBC drivers! We move data from Oracle to DB2 with ease and even showcase a way to move millions of rows of VSAM data into Oracle with only 5 lines of Java code! Take a look at the webinar recording and see how you can benefit from this technology in your environment! To view the webinar recording at your leisure, follow the link below. http://streaming.progress.com/prc/datadirect/dd_moving_mountains/index.htm A link to the slides used in the webinar are below: http://img.en25.com/Web/DataDirect/Bulk%20Webinar%20-%20Moving%20Mountains%200709.pdf -Jesse
Jul 24 A Brief History of Java and JDBC
While working on some JDBC training materials I decided to stress the importance of Java and JDBC on the computing industry. Having just come from this year’s JavaOne, I decided to do a short history of Java presentation to get everyone on the same page and level set the room. I started with my good friend Google - as any modern day gentleman would - to write down the history of my favorite language. This led me to a really nice timeline of Java History , put together by Sun Microsystems . I tried putting that into a Keynote presentation (PowerPoint for you non-Mac types) but it just didn’t fit; something was missing – I needed some oomph! So, I cracked open iMovie and went to it with a passion only a true Java Geek could muster. Putting together the movie, soundtrack, writing a script and narrating myself, and finally exporting to HD (my Mac makes this part simple). I wanted to show my appreciation for a language that has allowed me to earn my living and support my family doing something I truly enjoy. Thank you James and Sun Microsystems for developing a language that is really fun, I hope you and the community enjoy the movie as much as I enjoyed making it. There’s a small youtube movie embedded below, but you can make it full screen to see the HD version. Go ahead and drop by the YouTube page and leave a note saying how much you like Java, JDBC, or the movie. http://www.youtube.com/watch?v=WAy9mgEYb6o -Jesse
Jul 17 Making the impossible easy: failover for any application!
Anyone writing a modern day database application needs to think about high availability. The real problem is that it is complicated and expensive to code. For example, you could setup Oracle’s RAC environment ($$) but you’ll be faced with writing a whole lot of complicated, Oracle-specific code to support Oracle TAF. Additionally, if you have an existing application using a non-RAC replication solution TAF won’t work (TAF requires a RAC setup). Your other option is to simply use the DataDirect driver with your code and not have to worry about using Oracle RAC or Oracle TAF! I’m sure you’re leery and want to see it in action. Along those lines I wrote some code so you can demo the technology using a small Java program. In this scenario, a company is writing a web application to browse through golf courses here in North Carolina. The country clubs that the company is working for expect a seamless experience for their users (i.e. low tolerance). The data is replicated on two different servers and users get to browse through the course catalog (page per course), and each page displays course information from the database. The developer wants to ensure that the application doesn’t experience any errors or hiccups while a user is browsing the catalog. They want to make sure that if the database connection to the primary server fails while fetching course 5, the user gets course 6 when he hits the next button – not an error! In order to run the demo yourself, there are a few things that you’ll need: The application code is ( here ). The marketing guys want to know if you’re interested, so fill out the form – it’s not long, I promise!! The DataDirect Snoop application available here . A free evaluation download of the DataDirect Connect drivers, located here . Nobody likes to start off with some code and have to come up with the database preparation themselves, so we’ve made it really simple. The demo code has a simple setupDatabases() method to do just that. However, instead of executing a bunch of insert statements we’ve included a csv file that contains all the data needed for the example. We then take the csv file and bulk load it into the Oracle database (this is really fast – especially for large resultSets!). Loading a table this way is just a few lines of code: 1
2
3
4
// Load the data into the table from a csv file
System . out . print ( "Loading table from bulk data file..." ) ;
com. ddtek . jdbc . extensions . DDBulkLoad bulkLoader = com. ddtek . jdbc . extensions . DDBulkLoadFactory . getInstance ( con1 ) ;
bulkLoader. setTableName ( tableName ) ; This is much better than the for loop or other many-lined insert (think a bunch of PreparedStatements)and takes the hassle of moving tables from one database to another. However, this demo is really all about failover, so if you’re interested in learning more about bulk loading large data sets then you can learn more in our DataDirect JDBC User’s Guide and Reference available here . Now that we’ve setup our primary database and replicated the data on our alternate database (using bulk load) we are ready to test failover. If you pull the cable from the back of the machine or actually crash the primary server you may get undesirable responses from co-workers or your IT department, so let’s get creative! The snoop utility we provide to customers is specifically designed to help our support engineers gather data about the wire level traffic between the driver and server; however, it can be used to simulate a database failure too. To accomplish this, we only need to start the snoop program and have it sit between the application and primary server. This way we can just kill the window running snoop and it effectively terminates the connection with the primary server. Let’s go ahead and set the snoop utility to listen to port 1521 on our local machine, connecting to our primary server: Next we have to set our connection URL such that the primary connection goes through the snoop listener on our local machine so when we close the snoop window it effectively simulates a connection failure. Here is what our URL will look like: 1
2
3
4
static String URL1 = "jdbc:datadirect:oracle://nc-jdavis:1521;databaseName=CP31;user=test01;password=test01;" ;
// Connect to the database
Connection connection = DriverManager . getConnection ( URL1 + "failoverMode=select;failoverPreconnect=true;"
+ "AlternateServers=(nc-lnx02:1521)" ) ;   Note that the primary server is to my local machine (nc-jdavis) which goes through snoop to nc-lnx08 (in the snoop window). In the URL we add on our failover options to indicate that nc-linux02 is the alternate server and we want the select option for failoverMode. Setting failoverMode=select indicates to the driver that we want to failover seamlessly while going through the data – i.e. “Make it look like I never got disconnected!”. Additionally, we set a small performance option, failoverPreConnect, which causes the driver to connect to both the primary and alternate server during the first connect. This saves our application from incurring the cost of connecting during the failover process. It isn’t much, but at runtime every bit counts! So, let’s take a look at the code that displays the results: 1
2
3
4
5
while ( results. next ( ) ) {
      for ( int i = 1 ; i & lt ;= numCols ; i ++ ) {
          System . out . print ( "'" + results. getString ( i ) + "' \t " ) ;
      }
} You will immediately notice that this looks like a standard loop iterating through the results and printing them to the screen. So, how do you know that you failed over successfully? Easy – check the warnings object which will indicate when the failover happens. 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
 * This block of code checks for warnings and prints them out.
 * With this enabled you can see the warning that indicates
 * that the driver failed over successfully. Without this
 * printout you don't see anything differently as the failover
 * process is seamless to the application.
 */
SQLWarning warning = stmt. getWarnings ( ) ;
if ( warning != null ) {
      System . out . println ( ) ;
      System . out . println ( "Error code=" + warning. getErrorCode ( ) ) ;
      System . out . println ( "SQL state=" + warning. getSQLState ( ) ) ;
      System . out . println ( warning. getMessage ( ) ) ;
     stmt. clearWarnings ( ) ;
      System . out . println ( ) ;
}  Why don’t we show something that indicates the failover? We do not want to have to change our code to add failover client side – we want it to work with our middleware out of the box (i.e. – no client code changes). Additionally, if the application was being developed using a packaged application framework (think Hibernate or Cognos) then you can’t change the application code which makes using our failover mechanism easy to incorporate in any application architecture. Now run the application and notice the output is formatted for easy reading. You see the successful connection information for the server as well as the rows of golf course information: Connected with Oracle 4.0.027003 (040303.014800) to Oracle 11.1.0.0.0 Database Server Information ---------------------------------------------------------- ServerName: Oracle SeverMajorVersion: 11 ServerMinorVersion: 1 ID(ID) COURSENAME(COURSENAME) ADDRESS(ADDRESS) WEBSITE(WEBSITE) ========================================================================================================== '1' 'Devils Ridge' '5107 Linksland Drive, Holly Springs, NC 27540' 'www.clubcorp.com' '2' 'Finley Golf Course-UNC' '222 Finley Golf Course Rd, Chapel Hill, NC' 'tarheelblue.cstv.com' '3' 'Hillandale Golf Course' '1600 Hillandale Rd, Durham, NC' 'www.hillandalegolf.com' '4' 'Prestonwood Country Club' '300 Prestonwood Pkwy, Cary, NC' 'www.prestonwoodcc.com' '5' 'Pinehurst' '1 Carolina Vista Drive, Pinehurst, NC' 'www.pinehurst.com' '6' 'Lochmere Golf Club' '2511 Kildaire Farm Rd, Cary, NC' 'http://www.thegolfcourses.net/golfcourses/NC/5581.htm' Error code=0 SQL state=01000 [DataDirect][Oracle JDBC Driver]Your connection has been terminated. However, you have been successfully connected to the next available alternate server: nc-lnx02:1521;. '7' 'MacGregor Downs Country Club' '430 Saint Andrews Ln, Cary, NC' 'http://www.thegolfcourses.net/golfcourses/NC/5582.htm' '8' 'Forest Creek Golf Club' '200 Meyer Farm Dr, Pinehurst, NC ' 'http://www.thegolfcourses.net/golfcourses/NC/15017.htm' '9' 'Rock Creek Country Club' '2201 Country Club Rd, Jacksonville, NC ' 'http://www.thegolfcourses.net/golfcourses/NC/5714.htm' '10' 'Jacksonville Country Club' '2201 Country Club Rd, Jacksonville, NC' 'http://www.thegolfcourses.net/golfcourses/NC/5713.htm' -= Successful Completion =- Putting the logic of failover in the application is tedious and expensive. Let the middleware worry about the failover and repositioning logic so you can focus on satisfying the country club owners! Making sure that the application failover can handle connection failures in a standard way is key to ensuring the stability and uptime required by your customers. For more on how the DataDirect Connect for JDBC drivers implement failover, go here . Here is a PDF version of this Blog posting: testing-connection-failover .
Jun 11 JavaOne ‘09: A Data Geek's Recap
I’ve had a few days to come off of the Geek High that one gets when completely immersed in a tech conference and thought I would write my recap and highlights. First, the opening keynote was delivered by Jonathan Schwartz , and the technology announcements and demos were pretty cool: A new Java Store to enable Java Developers to distribute their applications worldwide A really cool demo of JavaFX being embedded in a flat panel TV (LG) showing Big Buck Bunny Sony Pictures showing off some fancy Blu-Ray Java tech One really nice video of the past 14 years of Java and how it’s changed. My favorite part here was the cartoon characters which resembled the famous Sun employees. After which, James Gosling launched the t-shirts and I finally got one (been going to JavaOne since 2002) New version of GlassFish (v3) and NetBeans The Sun Cloud later this year and project kenai (Think amazon EC2 on steroids and SourceForge on steroids). The demo of the Sun Cloud made EC2 look like a toy in terms of UI experience. Microsoft had an interesting keynote on interoperability between Java and .NET – was a little awkward and left some questions (more @ PCWorld here ). Scott McNealy presented Larry Ellison some flags for his boat that spell JAVA but mean something completely different. As a member of the JDBC Expert Group (EG) going to JavaOne does mean some work. The EG meets and we nail down what we’re pushing into the next version of JDBC (v4.1) which is due out in Java SE 7 next year (I’ll follow up with another post on that topic). This year during that meeting I was asked to present an idea during our BoF session that evening! Not much prep time, but it was really fun anyway. Thanks to those of you who were there and didn’t throw things at me. The final thing I’ll note on the conference was that attendance was around 15,000 – everyone was expecting much lower due to the economy. Those of us who were able to go were excited about Java and where it’s headed (just do a twitter search for JavaOne).  Loads of new technology, performance enhancements, and products to evaluate made for an awesome experience! Here’s to next year and the hope that Oracle keeps JavaOne alive! Technorati Tags: Java , JavaOne , Cloud , JavaFX , JDBC
Jun 1 See you at the JDBC BoF at JavaOne 2009!
Wondering what the next version of the JDBC specification will look like? What about that issue you logged; will it be fixed? What is JDBC 4.1 going to have in terms of new functionality? Join the JDBC Expert Group (of which I’m proud to be a member) as we cover these topics Tuesday (tomorrow) night at the JDBC BoF. Here are the details: BoF-4926: JDBC 4.1 Specification community Discussion, Room HE 134 This BOF session brings together members of the JDBC™ Expert Group and other people interested in finding out more about the features being targeted for the JDBC 4.1 specification. Come hear the latest details about the features under consideration, and express your opinions about the JSR to the specification lead and members of the expert group. They will use this session as an opportunity to gather input on features they should consider adding to the JDBC specification to support the latest features added to the SQL standard or that are available in other client APIs. The JDBC 4.1 technology is being targeted for Java™ Platform, Standard Edition 7 (Java SE 7 platform). See you there! -J
May 29 Options for Fine Tuning Memory Usage in Hibernate using Oracle
Suppose you’ve been tasked with tracking down the memory usage of your application you’ve written with Hibernate . You’ve traced and tuned, and you think you should be able to squeeze more out of your database drivers. For this specific example we’ll say that we need to tune parameter bindings. In order to more accurately control the amount of memory the driver allocates for each parameter in the PreparedStatement using Oracle's Thin driver, you must use the OraclePreparedStatement.defineColumnType() method (which is not part of the JDBC specification). WARNING! Note that if you re-bind your parameters on a subsequent execute using larger data sizes then the driver will be silently truncate to the size specified – which is bad. Also, due to the fact that Hibernate abstracts the actual JDBC calls themselves, you lose the power to customize these calls unless you modify the Hibernate code itself (casting the PreparedStatement to an OraclePreparedStatement in the process – Yuck!). This is generally unacceptable as it’s costly to modify the Hibernate code and you have to duplicate the code changes every time you upgrade the version of Hibernate you’re using. So, there goes option 1. Tuning memory on a per statement basis with the Connect for JDBC Oracle driver is much less costly; with our drivers you just set a connect option ( initalColumnBufferSize ) to set the initial size you want us to try for each parameter. Score! Now we don’t have to change Hibernate code to tune the app! Also, we don’t have the limitation of truncating the data on subsequent executes and binds; we will auto-adjust for the parameter’s size so there's no need to spend time analyzing every parameter binding. So, option 2 seems to be the way to go – it’s easy to use and doesn’t require modifying Hibernate’s internals to get it done!
May 26 Worldwide Data Mining: Wolfram Alpha!
For all you data geeks out there, there’s a new world wide data mining tool on the block, released just last week! Wolfram Alpha was developed by scientist Stephen Wolfram and according to their site, “Today's Wolfram|Alpha is the first step in an ambitious, long-term project to make all systematic knowledge immediately computable by anyone.”  It’s nothing like Google actually, as Google is searching data and this is computing data, but this could have a similar effect on the power of data and the internet! Computing answers based on data is powerful, and once you get the hang of it you can see that they’re nothing alike, but it’s really fun: Hitchhiker's aside, this is one tool that has really neat applications for getting not only the data, but the relationships between the data. For instance, put up PRGS and Apple and you’ll see the relationships between the companies as well as their individual data. Or, type in your name and see the number of those currently living with your same name (male or female) as well as when your name was popular charted over time. You can also export all these reports via PDF which is also nice so you can take it with you! Go ahead, click away and give it a try – something new to play with in the data space is good news – looking forward to where this can go !
Jan 24 JDBC Back to Basics: Part 1: Connecting
In this JDBC Basics series we'll go through the basic steps needed to get a knowledge of JDBC. Following this series we'll go through more advanced features of JDBC drivers, such as advanced security (Kerberos, etc…), performance tuning, etc.. For completeness, we'll show code examples for SQL Server, Oracle, DB2, Sybase, Informix, and MySQL as we know everyone in the world doesn't use the same database to store data. The following posts are currently available in this series. This list will be updated as posts are written and will be contained at the top of each post in the series. Connecting (this post) So, you want to write a Java application to get some data - you've come to the right place! Getting connected and fetching your data is easy using the JDBC Standard API that comes in the JDK. Let's jump right in by throwing out some code for connecting to SQL Server: 1
2
3
Class . forName ( "com.ddtek.jdbc.sqlserver.SQLServerDriver" ) ;
String url = "jdbc:datadirect:sqlserver://nc-pgm1:1433;databaseName=master" ;
Connection con = DriverManager . getConnection ( url, "user1" , "pass1" ) ; There we go, easy enough. The first line which has the Class.forName is not necessary if you are using a driver that supports the JDBC 4.0 autoloading feature and Java SE 6. Therefore, you could remove this line altogether leaving you with 2 lines to connect to your SQL Server database. The URL is easy to deciper as well - he first part is which driver you want to use “jdbc:datadirect:sqlserver”, followed by the server machine name (or IP address), port number, and database that you want to connect to. Lastly, you get the actual connection object passing in the url, user, and password. We'll go over Kerberos, Windows Auth and other security specifics in another post. Ok, so what do you do after connecting? In my demo application, I like to print out some server information from the DatabaseMetaData object (helps to make sure I'm using what I think I am). Here's the code: 1
2
3
4
5
DatabaseMetaData dbmd = con. getMetaData ( ) ;
System . out . println ( "nConnected with " + dbmd. getDriverName ( )
+ " " + dbmd. getDriverVersion ( )
+ " to " + dbmd. getDatabaseProductName ( )
+ "n" ) ; This gives us a nice line that shows what you got connected to and with what driver version. Helps a ton when you're checking your output or have to send the output to someone else to look at. Well, that's it for connecting - pretty straightforward. We'll continue next time with a different driver and start creating and working with tables!
Powered by Feed Informer