JDBC Connection for DB2 on iReport

I keep getting an error message when trying to create a new connection for a db2 database:

COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver] SQL1013N The database alias name or database name "db_name" could not be found. SQLSTATE=42705

I definitely made sure to specify the server name, port, and user name, etc correct but no matter what type of jdbc connection string used, jasper keeps failing.

The fix for me was to actually create a new IBM DB2 ODBC data source as follows:

  1. Administrative Tools -> Data Sources
  2. System DNS -> Add -> IBM DB2 ODBC DRIVER.
  3. Fill in a data source name for this connection.
  4. Add a new database alias. Fill in user and password information.
  5. Under TCP/IP tab, fill in the database name and alias (I had it set to my database name), host name, and port.

Back in iReport, when you create a new database connection, make sure the configuration looks like this:

  • JDBC Driver=COM.ibm.db2.jdbc.app.DB2Driver
  • JDBC URL=jdbc:db2:DB_NAME

Make sure to enter the right database name, user name, and password. Test the connection and it should work.

DB2 databases on same box

When you are working with a few db2 databases and you install it on the same box, you get into a situation where you have to know how to connect to each different databases. The easiest way is making sure you are sourcing the right db2profile file depending on the installation and use that, like db2inst1 or db2inst2.

. /home/db2inst2/sqllib/db2profile

If you are able to get a db2 connection up, you can try doing this command, to know what profile you have loaded.

db2 get dbm cfg | grep SVCE

That will return to you the service name, and then you can find out what service port the service is using,

grep service_name /etc/services

WAS Fails to Start

While I was trying to do a startServer on the websphere application server, I got an error message saying that the system could not start because of initialization problems. I found the native_stderr.log file with the following error messages:

JVMSHRC020E An error has occured while opening semaphore
JVMSHRC017E Error code: -308
JVMDUMP006I Processing Dump Event "abort", detail "" - Please Wait.
JVMDUMP007I JVM Requesting System Dump using '/opt/WebSphere/AppServer/profiles/AppSrv01/core.20071102.064046.5888.dmp'
JVMDUMP010I System Dump written to /opt/WebSphere/AppServer/profiles/AppSrv01/core.20071102.064046.5888.dmp
JVMDUMP007I JVM Requesting Snap Dump using '/opt/WebSphere/AppServer/profiles/AppSrv01/Snap0001.20071102.064046.5888.trc'
JVMDUMP010I Snap Dump written to /opt/WebSphere/AppServer/profiles/AppSrv01/Snap0001.20071102.064046.5888.trc
JVMDUMP007I JVM Requesting Java Dump using '/opt/WebSphere/AppServer/profiles/AppSrv01/javacore.20071102.064046.5888.txt'
JVMDUMP010I Java Dump written to /opt/WebSphere/AppServer/profiles/AppSrv01/javacore.20071102.064046.5888.txt
JVMDUMP013I Processed Dump Event "abort", detail "".

That is the JVM looking for a resource, and it was locked because the system didn’t shut down properly. There’s a folder in /tmp/javasharedresources that contains the locked items. Remove the contents in that folder and try to restart WAS. It should come up.

Oracle Column Format

When I’m running oracle through sqlplus in a script to select tables for reporting purposes, sometimes I end up with a lot of unnecessarily long column widths that should be no more than a few characters long. We can solve this by putting the column command in front of our select query:

COLUMN site FORMAT A5
COLUMN name FORMAT A20
SELECT site, name FROM dept;

Check here for more formatting styles.

MS SQL Unable to start MSSQLServer

I recently had to change my user account password. After that, I found that my instance of MS SQL was unable to get started automatically. Manually trying to restart the MSSQLServer service from the system tray and in enterprise manager, fails with the following error:

SQL Server Service Manager
An error 1069 - (The service did not start due to a logon failure.
) occurred while performing this service operation on the MSSQLServer service.

The problem is that in Administrative Tools -> Services, the MSSQLSERVER service was running under my account name, but the password was not changed to reflect the new one. Going into Log On properties and updated the password allowed me to start the service again.

Posted in MS SQL. 1 Comment »

MS SQL Select Query Slow

Sometimes, database performance can degrade too much and queries start taking a very long time to return. This is mostly due to having no indexes or having an out-of-date index. You can run this to recollect statistics on the indexes and also another to rebuild the index that’s bad.

sp_updatestats
dbcc dbreindex (table_name)
dbcc dbreindex ('database.dbo.table_name')

This will generally improve poor database query performances. If it doesn’t help, you can try diagnosing what indexes you have set up for that particular table or view.

Recovering Administrator Password in Windows

I had to fix a problem in the registry. And to do that, I needed to use Windows XP Recovery CD (installation CD choose R for recovery console). It kept prompting for an administrator password, even though I never had specified one. I found this little program that does a nice job at changing the Administrator’s password, even allowing me to disable that requirement altogether.

String substitution in list of files

I had a list of files that contained a string that I wanted to replace. I’ll break down the steps to doing simple scripting in UNIX. In windows try to get a copy of UNIX tools.

Searching and replacing in UNIX can be done with sed. An example of replacing apples to oranges in the file fruits would be as follows (in Windows cmd prompt, use double quotes instead of single quotes):

sed -e 's/apples/oranges/g' fruits.txt
cat fruits.txt | sed -e 's/apples/oranges/g'

So we can always redirect the stdout from sed to a file with:

sed -e 's/apples/oranges/g' fruits.txt > new_fruits.txt
cat fruits.txt | sed -e 's/apples/oranges/g' > new_fruits.txt

I couldn’t find a simple way to do a list of files though. Even something like this wouldn’t solve the problem of replacing each file with the changed value.

find . -name '*.txt' | xargs -i sed -e 's/apples/oranges/g' {}

This fails to do what I need because I have no way of redirecting the output to unique files. I found a nice way to do this whole thing with perl.

perl -pi -e ‘s/apples/oranges/g’ *.txt

Here’s the list of arguments for perl that I used:

p - creates a loop and prints out each line of each file passed in
i - does < input.txt > output.txt and takes care of renaming output file for you
e - executes the code

So, I conclude that perl is pretty nifty.

Posted in Perl, UNIX. 1 Comment »

DB2 Tablespaces Pages Full

Occasionally, if the tablespaces in db2 isn’t system managed, it can get full. Your application might fail from…

DB2 SQL error: SQLCODE: -289, SQLSTATE: 57011, SQLERRMC: TBSPNAME

This tells you the tablespace that probably ran out free pages. You can do the following to add additional pages to this tablespace.

DB2 CONNECT TO database_name
DB2 LIST TABLESPACES SHOW DETAIL
DB2 "ALTER TABLESPACE tablespace_name EXTEND (ALL 100000)"

This should resolve a lot of user managed tablespace out of page space issues.

Posted in DB2. 5 Comments »

Oracle 10g Windows Host Credentials

I get this error after adding an oracle user, “oracle” and trying to use it for the host credentials:

Error - Connection to host as user oracle failed: ERROR: Wrong password for user

I find that you have to actually, go into Control Panel -> Administrative Tools -> Local Security Settings ->  Local Policies -> Log on as a batch job -> add the “oracle” user to this.  This should succeed then.  Your “oracle” user should probably also be a member of the “ora_dba” group.

Posted in Oracle. 3 Comments »
Create your own website, free on WordPress.com.Create your own website.
Start free