************************************* * * * DB/C Newsletter * * October 1999 * * * ************************************* News and Comments Every so often I hear a comment that goes something like this: "With all the emphasis on Java, it seems like Subject, Wills and Company is abandoning DATABUS." We are not abandoning DATABUS. Yes, SWC is doing quite a bit with Java. But we are very much committed to DB/C DX. Here is an excerpt from a comment I made in this space in May of this year: "... Subject, Wills & Company is absolutely committed to supporting and enhancing DB/C for many years to come. As I said a few months ago, software is forever. DB/C source programs don't wear out. As we move to a subscription system for support of DB/C products, there will be continuing income to SWC as long as DB/C remains in use. We foresee this lasting for many years." That said, many of us in the DATABUS community have come to the realization that we can no longer hope for DATABUS to become generally accepted by the larger computing community. It's just not going to happen. In the past there were dozens of programming languages being used for business-oriented programming. In that environment, using a little-known language was acceptable to a majority of potential customers. Things have changed. Today, many business decision makers that are non-programmers are somewhat knowledgeable about computers and programming. They feel competent to judge programming languages. They're not. Regardless, they judge all of the merits of an application including the language it's written in. If they haven't heard of a particular language, they either judge it to be bad because they've not heard of it, or they think they won't be able to find any programmers to support their programs. Regardless of the validity of their concerns, applications written in DATABUS are dismissed immediately. I call this the "political correctness" factor. We in the DATABUS community must admit that DATABUS is not politically correct. As I've said before - Java is very similar to DATABUS in many technical respects. However, most importantly, it is the opposite of DATABUS in political correctness - Java is acceptable to almost all who judge it. So if you still want a portable language to write business applications, I suggest you adopt Java. Aside from learning a completely new language and replacing all of your development tools, there is a bigger problem - what do you do with your thousands (millions?) of lines of DATABUS and how do you make the transition? That's what DB/C JX and DB/C FS are all about. They're a bridge from DATABUS to Java. Some companies are crossing that bridge now. Others will cross in a few years. Some will just throw out their DATABUS applications after they rewrite their applications (what a waste!). At Subject, Wills & Company, we plan to make the bridge crossing as painless as possible. This month's article is about a tool for crossing the bridge. The tool, which is new in DB/C FS 2.1, is a class library that allows Java programs to access DB/C files managed by a DB/C FS server using traditional DATABUS (non-SQL) access methods. I realize that many readers of this newsletter aren't fluent in Java (yet), so the article is written in a manner that should be understandable to DB/C programmers as well. don.wills@swc.com ***************************************************************************** File Oriented Access to DB/C FS Managed Files Using Java There are several ways to access files managed by a DB/C FS server. Generally, they are organized into SQL and non-SQL access methods. The SQL access methods are ODBC (Windows 95/98/NT/2000) and JDBC (any operating system that supports Java). DB/C DX and DB/C JX provide non-SQL access to files managed by a DB/C FS server. And now with DB/C FS 2.1, any Java program can access files in a non-SQL manner using the DB/C FS Java Client Programming Interface. In the remainder of this article, sentences contained in { } brackets are information for Java programmers. If you don't know Java, you can ignore these sentences without losing understanding of what's going on. { The DB/C FS Client Programming Interface code is contained in the com.swc.fs package and is distributed in the fs.jar file. The following code samples omit the import com.swc.fs.*; statement. } The first step in using the DB/C FS Java Client Programming Interface is to create a connection to the DB/C FS server. To do this, you use the Connection class. The connection is actually made when the Connection class instance is created. Here is some sample code: Connection cnct; cnct = new Connection("server1.swc.com", "main", "user", "pswd"); In this code, the first line defines the variable named cnct which will hold a reference to a Connection. This is similar to the concept of a DB/C address variable. The second line creates an instance of a Connection and stores a reference to it into the cnct variable. The most similar concept in DB/C is to execute a LOADMOD statement followed by a call to a ROUTINE in that loadmod. The "server1.swc.com" operand is the name of the DB/C FS server. This operand is a complete Internet address or name. Thus it could have been specified with an IP address such as "207.208.157.40". The "main" operand is the name of the database. "user" is the user name and "pswd" is the password. These are the normal DB/C FS database, user and password fields that are specified in the the DB/C FS configuration files. { If the Connection cannot be created (e.g. the password is wrong), then a ConnectionException is thrown. } Once the connection is established, files can be opened and records can be read and written. Here is a code fragment that opens an existing, fixed length records file named "cust.txt" for random and sequential access: File file1; file1 = new File(cnct); file1.setdatafile("cust.txt"); file1.setoptions(File.FIXED | File.FILEOPEN); file1.open(); The statement in the first line defines the variable named file1. This is similar to defining a FILE variable in DB/C. The statement in the second line creates an instance of a File that is associated with the Connection (and thus the DB/C FS server at server1.swc.com) that was previously created. The statement in the third line sets the data file name to be opened. The style of having the file1 variable precede the method name is mystifying to most DATABUS programmers at first. This is a typical style for many object oriented programming languages. After a while, it becomes second nature. The statement in the fourth line sets two options: fixed length records and a FILE type open (as opposed to IFILE and AFILE). The vertical bar is the or operator. The values being or'd together are just integer constants. The statement on the fifth line actually causes the file to be opened. After the file is opened, records can be accessed sequentially or randomly, just as in DATABUS. Here is code that reads the first record with a random read: int n1; char[] rec1 = new char[80]; file1.setrecordbuffer(rec1); n1 = file1.readrandom(0); The statement in the first line defines an integer variable named n1. The statement in the second line defines and allocates an array of 80 characters. The name of the array is rec1. The statement in the third line associates the array with the File instance that file1 refers to. The statement in the fourth line causes record number 0 (the first record in the file) to be read into the character array. The value returned by the readrandom method is the number of characters moved into the array. In this case it will always be 80 if a record is successfully read because the file contains only fixed length records. However, if the end of file is encountered, the value -1 is returned. { Errors that may occur during open, read, write, etc. cause a FileException to be thrown. All FileException instances provide an integer error value that is the same as its DB/C counterpart, but without the leading character. For example, a format error (F 201 in DB/C) causes a FileException whose geterror() method returns 201. Additionally, a description of each FileException is available via its toString() method. } The DB/C FS Java Client Programming Interface provides all of the sequential, random, indexed and AIM indexed access capabilities that are available in DB/C, including FILEPI and record locking. The DB/C FS 2.1 Reference provides a complete description of each of the classes and method that are provided. ***************************************************************************** DB/C Class Schedule Class: DB/C DX and JX Language Fundamentals Date: January, 2000 (tentative) Location: Oak Brook, Illinois For information, contact Judi Tamkevic at: voice 630.572.0240 email dbc@swc.com ***************************************************************************** Subscribing to the DB/C Newsletter If you don't already have the DB/C Newsletter delivered to your email address and would like to have it emailed to you when it is produced, just send an email message to 'request@swc.com' and put the line 'subscribe dbcnews' in the body of the email message (omit the ' characters). The newsletter will be delivered to the email address from which the message was sent. To stop delivery, put the line 'unsubscribe dbcnews' in the body of the message.