ivetic.net – My Java/J2EE blog

Installing Tomcat, Apache and MySQL on a Windows 2003 server

Posted by: Aleks on: February 13, 2009

I successfully installed a Java application (Tomcat, Apache and MySQL ) on a Windows 2003 server, and this was a tricky process.

Here are some guidelines:

These are all the install files that I’m using:
jdk-1_5_0_17-nb-6_5-windows-ml.exe
mod_jk-1.2.27-httpd-2.0.63.so
mysql-essential-5.0.67-win32.msi
mysql-gui-tools-5.0-r15-win32.msi
apache_2.0.63-win32-x86-openssl-0.9.7m.msi
apache-tomcat-5.5.27.exe

TOMCAT change: Don’t forget to increase the heap size. Also, you must set this value:
-Dorg.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false
(Otherwise you will get this error: Attribute value  is quoted with “” which must be escaped when used within the value)

Shutdown all ISS Services, otherwise you won’t be able to install Apache as a service.

Enable Firewall, otherwise someone might hack into your server!

This is how you should create your certs:
“C:\Program Files (x86)\Apache Group\Apache2\bin\openssl” req -config openssl.cnf -new -out server.csr
“C:\Program Files (x86)\Apache Group\Apache2\bin\openssl” rsa -in privkey.pem -out ssl.key/server.key
“C:\Program Files (x86)\Apache Group\Apache2\bin\openssl” x509 -in server.csr -out ssl.crt/server.crt -req -signkey ssl.key/server.key -days 1365

Finally, here are my httpd.conf and workers.properties  files.
Please let me know if you have any questions, I’m more than glad to help anyone out with this!

SQL Code – how to convert timestamp to DATETIME

Posted by: Aleks on: February 13, 2009

select dateadd(second,last_update_time,’01/01/1970′) from YOUR_TABLE_NAME

(obviously, last_update_time is the timestamp in seconds)

The previous example works with JDBC 3.0. However, my server doesn’t use the 3.0 implementation, so I had to do it by using a stored procedure which returns the key for the inserted row (SCOPE_IDENTITY() value).

Here’s the skeleton for how I did it:

CREATE PROCEDURE YOUR_STORED_PROCEDURE_NAME (
 [YOUR_PARAMETERS_GO_HERE],
 @RowId INT OUTPUT
)AS

INSERT INTO YOUR_TABLE [ETC ....] ;

SET @RowId = SCOPE_IDENTITY();
select @RowId;
GO

Here’s an article that talks about how : https://www.ibm.com/developerworks/java/library/j-jdbcnew/

And here’s a code snippet:

PreparedStatement ps = conn.prepareStatement(sqlCode,
     PreparedStatement.RETURN_GENERATED_KEYS);

……

ps.executeUpdate();
   //Get the value of the key inserted by this statement
   ResultSet rs = ps.getGeneratedKeys();
   if ( rs.next() ) {
       // Retrieve the auto generated key(s).
       int key = rs.getInt(1);
       pOrder.setOrderId(key);
   }

What am I currently working on….

Posted by: Aleks on: January 16, 2009

Right now I have 2 major things going on in paralel:

1) I’m developing a J2EE FOREX application for ordering transactions and automatically executing orders. I’m using EXTJS as a front end. This project is divided into several phases, and one of the phases will be implementing R/T notifications about new orders. I am intending to use IBM’s SameTime for this purpose.

2) I’m working on installing Tomcat+Apache+MySQL+SSL+everything-else -from-an-old-server on a new Windows 2003 server for one of my clients…..This is never fun, I haven’t done this in a couple years, but I should still have notes around from the last time I’ve done it….

Connecting to a datasource from Websphere

Posted by: Aleks on: January 15, 2009

These are the steps that I had to do to connect to a database datasource from my Websphere application:

1) This is Java code:
Context ctx = new InitialContext();
DataSource ds = (DataSource) ctx
.lookup("jdbc/sqlServerDS");
Connection connection = ds.getConnection();

2) My web.xml has this entry:

 

 

 

 

 

 

<

resource-ref id=“ResourceRef_1231963089452″> 

 

<description></description> 

 

<res-ref-name>sqlServerDS</res-ref-name> 

 

<res-type>javax.sql.DataSource</res-type> 

 

<res-auth>Container</res-auth> 

 

<res-sharing-scope>Shareable</res-sharing-scope> 

 

</resource-ref>

3) Make sure that your ibm-web-bnd.xmi file has this entry that contains jndiName:

 

 

<

resRefBindings xmi:id=“ResourceRefBinding_1231963089452″ jndiName=“jdbc/sqlServerDS”> 

 

<bindingResourceRef href=“WEB-INF/web.xml#ResourceRef_1231963089452″/> 

 

</resRefBindings>

NOTE: You can set resource bindings by opening web.xml in your iRAD, and going to References tab. You can Add a new reference with the details from above.

4) On your local server, you have to setup your datasource’s JNDI name as: jdbc/sqlserverDS

The most common errors are:
javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context “java:”

Solution: do not use “java:comp/env/jdbc/sqlServerDS, use only jdbc/sqlServerDS)

How to import/export IE browser settings

Posted by: Aleks on: January 7, 2009

I recently encountered a problem where a user’s PC’s couldn’t open PDF files that were linked from our web site. This was an unusal behavior, considering that the application works just fine from every other developers’ computer, but this quirky behavior happens for every user from this certain group. After spending a couple hours manually messing with user’s IE settings without any luck,  I just decided to export all IE settings from my PC and import them to user’s browser.

To do this you will need to use “Files and Settings Transfer Wizzard” which comes installed on your XP machine.

How to export your IE settings

1) Go to: Start -> Accessories -> System Tools -> Files and Settings Transfer Wizzard.
2) Select “Old Computer” on the first screen.Click Next.

11
3) Select “Other” for the transfer method , and then select a folder where you want your files to be saved to. Click Next.

2
4) On this screen you can select what do you want to transfer. Select “Settings Only”, and check “Let me select custom list…” checkbox. Click Next.


5) Select only “IE security settings” and “IE Settings”. As you can see, there’s bunch of other options/settings available as well….

6) Click Next, and you are done. A folder will be created with all the files that you need. You should copy this folder to a computer on which you want to import these settings.
How to import IE settings

1) Go to: Start -> Accessories -> System Tools -> Files and Settings Transfer Wizzard.
2) Select “New Computer” on the first screen. Click Next.


3) On the next screen, select “I don’t need the Wizard Disk”. Click Next.


4) On the next screen, select Other, and then browse to the settings file that you exported from the other computer (in “How to export your IE settings” sections).

 

5) Click Next, wait some time until the process is done, restart your PC, and you are ready to go!

Writing High Performance SQL Code

Posted by: Aleks on: December 29, 2008

There is a great e-book on this topic: “Dissecting SQL Server Execution Plans” by Grant Fritchey.
Why is this query running slow? Is my index getting used? Why does this query run faster than this query? Well, have you even looked  at the execution plan?

Book Description

Execution plans show you what’s going on behind the scenes in SQL Server. They can provide you with a wealth of information on how your queries are being executed by SQL Server, including which indexes are getting used and where no indexes are being used at all; how the data is being retrieved, and joined, from the tables defined in your query; how aggregations in GROUP BY queries are put together and the anticipated load, and the estimated cost, that all these operations place upon the system. All this information makes the execution plan a vitally important tool in the tool belt of database administrator, database developers, report writers, developers, and pretty much anyone who writes TSQL to access data in a SQL Server database.
 
The goal with this book was to gather as much useful information on execution plans as possible into a single location, and to organize it in such as way that it provided a clear route through the subject, right from the basics of capturing plans, through their interpretation, and then onto how to use them to understand how you might optimize your SQL queries, improve your indexing strategy, spot some common performance issues, and more.

 

 

 

 

How to create an MDB connected to MQ

Posted by: Aleks on: December 26, 2008

Use a Message Driven J2EE Bean (MDB) to ‘listen’ to a queue and fire when a message arrives.  The message is removed from the queue once the MDB processes it (calls onMessage()).

 

  1. Login to admin console (right click on server, choose “Run Administrative Console”
  2. Go to Resources | Websphere MQ JMS Provider
  3. In “Additional Resources” section, choose “Websphere MQ Queue Destination”
  4. Click [New]
  5. Enter the required fields
  6. Go back to Resources | Websphere MQ JMS Provider
  7.  In “Additional Resources” section, choose “Websphere MQ Queue Connection Factories”
  8. Click [New]
  9. Enter Name, JNDI Name, Queue Manager, Host, Port, Channel, Transport Type
    e.g.
  10. Save changes in admin console
  11. Open up server configuration (double click server in Server tab)
  12. Goto EJB tab
  13. Under “Listener Ports”, click [Add…]
  14. Enter a name, and the connection factory JNDI name, and destination JNDI names you created above
  15. In J2EE Hierarchy, right click your EJB module (if you don’t have one, right click “EJB Modules”, then select New | EJB Project”), select New | Enterprise Bean
  16. Reselect your project, click [Next]
  17. Select “Message Driven Bean”, give it a name, click [Next]
  18. Enter the listener port name you created above.  Click [Finish]
  19. In your new bean, you can then put your logic in the onMessage() method, which will be called whenever a message appears in the queue.

 

Problems with iTunes, iPhone 3G and Windows XP

Posted by: Aleks on: December 22, 2008

I bought an iPhone 3G recently and for some reason my previously installed iTunes (on Windows XP) couldn’t recognize that the iPhone was plugged in! I had iTunes already installed, because I already have an iPod. I spent a couple hours trying to fix the issue, installing the latest version of iTunes didn’t help. Finally, these steps did it for me, and I was able to see iPhone in iTunes in the left hand side under “My devices”.

1) Uninstalled iTunes, Apple Mobile Devices, Apple Installer, Quicktime and Bonjour. (Make sure that ALL apple related software is cleaned up!!!)
2) Deleted iTunes folder from User <your login account> Music. (I skipped this step initially, and re-installation didn’t do anything for me)
3) Made sure iTunes directory deleted from Program Files.
4) Searched for and deleted all .itl files (iTunes Library Files).
5) Rebooted PC
6) Installed the latest version of iTunes 8 (available on Apple’s website).

Follow

Get every new post delivered to your Inbox.