Thursday, May 28, 2009

Know how to use split() method of String class in Java...!!!

Java 1.4 introduced a new method called split() in order to simplify a task of breaking string into substrings or tokens. It takes regular expression as parameter and breaks the string into substrings by matching this regular exp within the string.

Two methods are used for this purpose

1) split(String exp): In this exp is the regular expression and it will return an array of strings.

example:
String names= "Nagpur,Pune,Mumbai,Delhi";
String names[]=names.split(",");

O/P : When you iterate that array the output will be
Nagpur
Pune
Mumbai
Delhi

2) split(String exp, int max)
: Now this method has two parameters
where exp- regular exp
max- number of times to apply that pattern.

Wednesday, May 27, 2009

Location for WebSphere Portal default Login Portlet ...!!!

If anybody working on IBM's default login portlet then you can find the location of the login.war at

[Drive]:\IBM\WebSphere\wp_profile\installedApps\\PA_Login_Portlet_App.ear\login.war\WEB-INF\jsp\LoginView.jsp

Here LoginView.jsp is the default login view of your portal.

Tuesday, May 26, 2009

Exception: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified..!!!

It might be possible that when you try to establish connection with Database using JDBC:ODBC approach you can face the following exception
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

fix:

Delete the USER data source name and define it as a SYSTEM data source name.

In Windows 2000:
-> Start -> Settings -> Control Panel -> Administrative Tools ->
Data Sources (ODBC):
- User DSN : delete the specified User DSN
- System DSN : create a new System DSN

Monday, May 25, 2009

Know how to connect Microsoft Access Database using JDBC..!!!

Interested in connecting to Ms Access using JDBC..!!! The following post will guide you achieve this.

Microsoft has developed a data access method called ODBC, and MS Access databases understand this method. We cannot make a connection directly to an ODBC data source from Java, but Sun has provided a bridge from JDBC to ODBC. This bridge gives the DriverManager the understanding of how to communicate with an ODBC (ie a MS Access) data source.

As we know that we can get the connection object of java.sql.Connection with the use of DriverManager class. We tell the DriverManager what type of driver to use to handle the connections to databases, and from there, ask it to give us a connection to a particular database of that type.

So the first thing we'll do is set up our DriverManager and let it know that we want to communicate with ODBC data sources via the JDBC:ODBC bridge. We do this by calling the static forName() method of the Class class. Here is an entire program that accomplishes what we're after:

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Now their are two ways to get Connection Ms Acess :

1)Get a connection by direct access: I will not suggest you to go for this approach, but still for your understanding below is the code for this approach. Here get a connection is to go directly after the MS Access database file

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String filename = "c:/java/customerInfo.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
// now we can get the connection from the DriverManager
Connection con = DriverManager.getConnection( database ,"","");
}

catch (Exception e) {
System.out.println("Error: " + e);
}

2)Set up a DSN and get a connection through that: This approach is the recommended one.

Microsoft has provided a method to build a quick Jet-Engine database on your computer without the need for any specific database software (it comes standard with Windows). Using this method, we can even create a blank Microsoft Access database without having MS Access installed!

As we learned earlier, MS Access data bases can be connected to via ODBC. Instead of accessing the database directly, we can access it via a Data Source Name (DSN). Here's how to set up a DSN on your system:

1. Open Windows' ODBC Data Source Administrator as follows:
* In Windows 95, 98, or NT, choose Start > Settings > Control Panel, then double-click the ODBC Data Sources icon. Depending on your system, the icon could also be called ODBC or 32bit ODBC.
* In Windows 2000, choose Start > Settings > Control Panel > Administrative Tools > Data Sources.
2. In the ODBC Data Source Administrator dialog box, click the System DSN tab.
3. Click Add to add a new DSN to the list.
4. Scroll down and select the Microsoft Access (.MDB) driver
5. Type in the name "mdbTEST" (no quotes, but leave the cases the same) for the Data Source Name
6. Click CREATE and select a file to save the database to (I chose "d:\java\mdbTEST.mdb") - this creates a new blank MS Access database!
7. Click "ok" all the way out

Now our data source is done! Here's a complete program showing how to access your new DSN data source:

String dataSourceName = "customerInfo";
String dbURL = "jdbc:odbc:" + dataSourceName;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbURL, "","");
}
catch (Exception err) {
System.out.println( "Error: " + err );
}


Now you have established connection with your database successfully.

Thursday, May 21, 2009

Know how to retrieve components of a date using SQL...!!!

You can retrieve different components of date from timestamp using SQL functionDATEPART. You can extract date components like YEAR, MONTH, DAY, HOUR, MINUTE, SECOND using this Datepart function. The syntax for using this function is

datepart(date component to retrieve, date)

Example: Suppose you want to retrieve year component from customer table's DOB column having timestamp type, the query will be like

Select datepart(year, DOB) from customer where cust_name='xyz'

ResultSet:- 1984

Same way you can use:
datepart(day, DOB) for day
datepart(minute, DOB) for minute
datepart(month, DOB) for month
datepart(hour, DOB) for HOUR
datepart(second, DOB) for second

The above function works fine with SQLServer but with Oracle and MySql I guess it wont work. In that case you can use extract(year from DOB).

Tuesday, May 19, 2009

Know how to get current date timestamp in SQL..!!!

In my recent project i was looking for a built-In SQL function that returns me the current date as timestamp. As we know Date values are stored in Tables as timestamp.A SQL timestamp is a record containing date/time data, such as the month, day, year, hour, and minutes/seconds.
SQL offers a built-in function called GETDATE() that returns the current date in the form of a SQL timestamp.
Hence to get current date run the below query:
SELECT GETDATE();

and the timestamp result will be
2009-05-20 01:23:45.150000.(Current Date)

Friday, May 8, 2009

Know how to Retrieve a Signer Trust Certificate from a remote endpoint?

To rerieve a Signer Trust Certificate from a remote endpoint and save to RAD's local Key Store, you may use either:
Jython Administrative Scripts
RAD WAS WTE Admin Console as shown below.

Launch the WAS Administration Console


• Open the Navigation Menu Security folder on the left.
• Click SSL certificate and key management


  • Click Manage endpoint security configurations

  • Under Inbound -> [cellname] -> nodes
  • Click [nodename](NodeDefaultSSLSettings,null) (should be the upper link)


  • Click Key stores and certificates (on the far right)


  • Click NodeDefaultTrustStore (should be the 2nd link)


  • Click Signer certificates (on the far right)



  • Click the Retrieve from port button (in the upper area of the screen)


  • Supply the endpoint Host ( Web Service DNS alias)
  • Supply the endpoint Port (443)
  • Supply an endpoint Alias (anything you desire)
  • Click the Retrieve signer information button



  • Click OK


  • Verify the new certificate entry
  • Click Save (top of screen)


  • Logout of the Admin Console
  • Bounce the RAD WAS 6.1 WTE server