Wednesday, May 21, 2014

Command to login with command prompt in MySQL

C:\Program Files\MySQL\MySQL Server 5.6\bin>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.12 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Show the character set variables:


mysql> show variables like 'character_set%';
+--------------------------+----------------------------------------------------
-----+
| Variable_name            | Value
     |
+--------------------------+----------------------------------------------------
-----+
| character_set_client     | cp850
     |
| character_set_connection | cp850
     |
| character_set_database   | utf8
     |
| character_set_filesystem | binary
     |
| character_set_results    | cp850
     |
| character_set_server     | utf8
     |
| character_set_system     | utf8
     |
| character_sets_dir       | C:\Program Files\MySQL\MySQL Server 5.6\share\chars
ets\ |
+--------------------------+----------------------------------------------------
-----+
8 rows in set (0.18 sec)

mysql>


Ref:
 http://dev.mysql.com/doc/refman/5.0/en/show-character-set.html








Thursday, May 15, 2014

Handling Web page with DB Tag Library:

First, obtain the Jakarta DBTags binary distribution from the Apache Jakarta DBTags site. Copy dbtags.tld, the tag library descriptor file, to the /WEB-INF directory of your web application. Copy dbtags.jar, the tag library .jar file, to the /WEB-INF/lib directory.
Next, you need to modify the /WEB-INF/web.xml web application deployment descriptor file. Include the following taglib tag in theweb-app element of the web.xml deployment descriptor.

  http://jakarta.apache.org/taglibs/dbtags
  /WEB-INF/dbtags.tld
Then add the following directive to this article's example JSP file, SQLDBTags.jsp:
<%@ taglib uri="http://jakarta.apache.org/taglibs/dbtags" prefix="sql" %>
The prefix attribute of the taglib directive is the prefix of the tags used as they'll be used the JSP. The choice of sql is arbitrary, meaning you can use another name if you like.
Next we need to make the database driver classes available to the JSP. For Oracle, add the zip file /ora81/jdbc/lib/classes12.zip to the classpath. This completes the required configuration steps.

Obtaining a Database Connection

A database connection is required to work with the database. If a JSP scriptlet is used to obtain the connection, the JDBC driver class has to be loaded with:
Class.forName("");
and a JDBC connection is obtained with:
Connection conn =
    DriverManager.getConnection(url,
                                userName,
                                password);
With the DBTags tag library, a JDBC connection is obtained with the sql:connection tag. In the example JSP, SQLDBTags.jsp, a connection with a Oracle database is established with the Oracle OCI Type 2 driver as follows:

  SYS
  change_on_install
  jdbc:oracle:oci8:@OracleDB
  oracle.jdbc.driver.OracleDriver
The id attribute identifies the connection so that later tags can refer to it. The sql:driver is the database driver class name. Finally, the sql:userId, sql:password, and sql:url tags provide the other needed parameters to create a database connection; i.e., the same parameters needed for a getConnection() call.
In addition to the attributes and sql:connection tags used in the example JSP, the sql:connection tag syntax can also have the attributes dataSource, which specifies a DataSource object, and jndiName, which specifies a JNDI name of a datasource. A JNDI-named DataSource can also be specified through the tag sql:jndiName.
With the sql:connection tag, the JDBC connection is created and given an id that can be used by other tags in the JSP.

Creating a Database Table

To create a database table in a JSP scriptlet, a JDBC Statement has to be created with:
Statement stmt=conn.createStatement();
A database table can then created with:
stmt.executeUpdate("Create TABLE ..." );
With DBTags, a SQL database table is created with the sql:statement tag instead. In the example JSP, the table OracleCatalogis created with the columns Journal, Publisher, Edition, Title, and Author.
The sql:statement tag has an attribute, conn, which refers to the id of the SQL connection created in the previous section. The table is created as follows:

  <%--SQL query to create a table--%>
  
    CREATE TABLE OracleCatalog(Journal VARCHAR(25),
                               Publisher Varchar(25),
                               Edition VARCHAR(25),
                               Title varchar(45),
                               Author Varchar(25))
  
  <%-- execute the query --%>
  
The sql:statement tag has the attributes id and conn. id provides an identifier that can be used by other tags, and conn is the idof the connection we created earlier.
The SQL query to create the table is set with the sql:query tag. This query is then executed with the sql:execute tag, which has an attribute ignoreErrors. If this attribute is set to true, it ignores an SQLException generated during the compilation of a JSP, and does not throw a JSPTagException exception.
An sql:statement is also used to insert values into the newly created table.

  <%--SQL query to add values to a table--%>
  
    INSERT INTO  OracleCatalog VALUES('Oracle Magazine',
                                      'Oracle Publishing',
                                      'Jan-Feb 2004',
                                      'Designing Schemas',
                                      'Cameron O'Rourke')
  
  <%-- execute the query --%>
  

Generating a ResultSet from a Database Table

To run a query and get results in a JSP scriptlet, a ResultSet has to be created with:
ResultSet rs=stmt.executeQuery("SELECT ...");
The result set is iterated with code like the following:
while(rs.next()){
    String var=rs.getString("...");
}
With DBTags sql:resultSet tag is used to retrieve and iterate through a SQL query result set. The sql:getColumn tag retrieves the column values in a result set.
 
  
    select JOURNAL, PUBLISHER, EDITION, TITLE, AUTHOR
            from OracleCatalog
  
  
JOURNAL PUBLISHER EDITION TITLE AUTHOR
Inside of the sql:resultSet tag, we can use sql:getColumn tags to retrieve the value for a given column and put it in the HTML. In this case, we have a table row inside of the sql:resultSet, and inside each table cell (), we use sql:getColumn to populate the cell value. The result looks like the following:
JOURNALPUBLISHEREDITIONTITLEAUTHOR
Oracle MagazineOracle PublishingNov-Dec 2003Updating XQueryJason Hunter
Oracle MagazineOracle PublishingJan-Feb 2004Designing SchemasCameron O'Rourke

Updating a Database Table with a Prepared Statement

A prepared statement is a SQL query with ? symbols. The column values represented by the ? symbols are set with a separate set of tags. If a JSP scriptlet is used to update a database table with a prepared statement, a prepared statement has to be created with:
PreparedStatement stmt=conn.prepareStatement("UPDATE ...");
The column values are set with:
stmt.setString("...");
stmt.setInt("...");
The prepared statement is executed with:
stmt.executeUpdate();
A prepared statement with DBTags is generated with the sql:preparedStatement tag. In the example JSP, the database tableOracleCatalog is updated with a prepared statement, as follows:

  <%-- prepared statement SQL query --%>
  
    UPDATE OracleCatalog SET TITLE=?, AUTHOR=? WHERE TITLE=? 
  
  
    <%=title%>
    <%=author%>
    Updating XQuery
  
The column values in the prepared statement are set with the sql:setColumn tag. After updating the table, the example code query produces the following results:
JOURNALPUBLISHEREDITIONTITLEAUTHOR
Oracle MagazineOracle PublishingNov-Dec 2003Unicode Enables GlobalizationJonathan Gennick
Oracle MagazineOracle PublishingJan-Feb 2004Designing SchemasCameron O'Rourke
Finally, when the JSP is finished with the database connection, it closes it with the sql:closeConnection DBTags tag:

Conclusion

DBTags custom tag library is used for servlet specifications prior to Servlet 2.3. For Servlet 2.3 and 2.4 specification implementations, Jakarta's Standard Tag Library 1.1, which is an implementation of JavaServer Pages Standard Tag Library (JSTL) 1.1, should be used.

Wednesday, December 5, 2012

Proper logout link as follows after click on browser back button


http://www.javaworld.com/javaworld/jw-09-2004/jw-0927-logout.html?page=1


Tuesday, December 4, 2012

Factorial Program:


public class Factorials {

/**
* @param args
*/
public static void main(String[] args) {
System.out.println("Inside main class");
System.out.println("factorial of 5:"+fact(5));

}

static int fact(int num) {
if (num == 0 || num == 1)
return 1;
else if (num < 0)
return 0;
else
return num * fact(num - 1);
}
}

Monday, November 10, 2008

Poem Related to love

Every night I lay my head down on my pillow
I always think about you…Nobody on this Earth has ever made me feel so special the way you did
There are no words that describe the way you made me feel.

I lay in bed and try to sleep,
But get no rest, in love to deep.
I close my eyes and see you face…
The smile on your face
Set my heart afire…
The twinkle in your eyes
Make my temperature rises…
How much I stare you
Because you look better than all stars up there
I feel your touch and warm embrace…
We make sweet love on clouds of white
And passion flows all through the night
In dreams and shadows.

I have been waiting to hold you in my arms again for awhile…
You could find love, in depth of your heart…
But you can never lose it becomes embedded in there
You can never buy love or replace it, too.
Because you deeply care.
I want to be cherish
By a love that wont perish
And you are the key
When you open your door
I want to yell, “I’M YOURS!”
If only you would have me?

Love is the greatest thing in this world even though the universe
Make you feel an inner glows…
Your all loves with keep on burning in your heart.
A time in which you’re all loves become so strong and passion
That it doesn’t matter that you have to wait so long…to keep our loves alive.

To hold you one more time would make clouds parts of me…
And the sun would shines and I could feel its warmth…
You are like a rose with undying beauty and I am thorn undeserving…

The happiest day I will ever know
The one when you finally come near
And lean in…
For that special kiss that I will never forget…
And many memories of making you laugh and smile…

Special night falls on this day where I embraced every though of you…
The white full moon shines down and lights my window and this special so reddish with picture of roses paper....
Where I spill my all heart…all for you.
Always for you!

Tuesday, October 21, 2008

wah ajib lamhe

Kabhi kaha, Kabhi socha, Kabhi aise hi chal diye........

Sunday, October 19, 2008

my love

HEART is Special Word For LOVE
LOVE is Special Word for CARE,
CARE Is Special Word For FRIEND,
FRIEND is Special Word for U
AND
You R Special Person 4 Me

///////////////
Our first and last love is.. self-love
Overlook not your own opportunity