I18N and Database

http://docstore.mik.ua/orelly/java-ent/servlet/ch12_04.htm#ch12-31698
http://www3.ntu.edu.sg/home/ehchua/programming/java/JavaServletExamples.html
http://candidjava.com/struts-1x-i18n-internationalization-tutorial-with-example-programusing-link
http://www.kodejava.org/examples/220.html
http://www.devmanuals.com/tutorials/java/servlet/servlet-internationalization.html
http://www.web-tech-india.com/software/jsp_chat.php#options
http://www.codeforge.com/article/90068

Paging:

http://javahunter.wordpress.com/2011/01/31/ultimate-paging-practice-through-jquery-ajax/

<link rel="stylesheet" href="css/pagination.css" />
<script type="text/javascript" src="js/pagination/jquery.pagination.js"></script>
<script type="text/javascript">
        var _EVENT;
        var _MAX_DISPLAY_PAGES = 5;
        var _ITEMS_PER_PAGE = 4;
        jQuery(document).ready(function() {
        initPagination();
        });      
       
        function initPagination() {
                _EVENT = "load";
                        var totalItemCount = formObj.totalItemCount.value;
            jQuery("#pageLinks").pagination(totalItemCount, {
                callback: paginate,
                num_display_entries: _MAX_DISPLAY_PAGES ,
                items_per_page: _ITEMS_PER_PAGE
            });
         }         function paginate(pageIndex, container){
        var startOffset;
        var endOffset;
        var formObj = document.forms["dummyForm"];
        if (_EVENT != "load") {
            endOffset = (pageIndex + 1) * 4;
            startOffset = endOffset – 4;
            formObj.startOffset.value = startOffset;
                jQuery.get("dummy.html?operation=viewList", params, function(data){
                   jQuery(‘#resultArea’).html(data);
                });
        } else {
            _EVENT = "";
        }
       
        return false;
    }
</script>
<form name="paginationForm">
        <div id="resultArea">
                <!– The list of records to paginate will come here; maybe in a table form –>
        </div>
        <div id="pageLinks">
                <!– Page links will be rendered by JQuery plugin
                upon calling the paginate callback function for the first time –>
        </div>
       
        <input type="hidden" name="startOffset" />        
        <input type="hidden" name="totalItemCount" value="${pageList.totalItemCount}" />        
</form>

Style Sheet Switcher


$(document).ready(function() {
               //load silver automatically in ready

                 $("a.silver").click(function() {
                         $('head > link').last().remove();   //removes red and adds silver
                         $('head').append('<link rel="stylesheet" href="style2.css" type="text/css" />');
                   });

                 $("a.red").click(function() {
                        $('head > link').last().remove();  //remove silver - adds red
                        .append('<link rel="stylesheet" type="text/css" href="themes/silver/css/template.css"/>');
                          });
                    });
             });

"DataBase "


DataBase related quick notes:Normalization , Outer Join Vs Inner Join, Sample Stored Procedures, Tiggers etc.,

1 )   DataBase Normalization

Ans)

  • DataBase Normalization
    Sample Img 1
DataBase Normalization Forms



2 )   Database Outer Join VS Inner Join

Ans)

  • Database Outer Join VS Inner Join
    Sample Img 2
An inner join of TableA and TableB gives the result of TableA intersect TableB, i.e. the
inner part of a venn diagram intersection.
An outer join of TableA and TableB gives the results of TableA union TableB, i.e. the
outer parts of a venn diagram union.
Examples
Suppose you have two Tables, with a single column each, and data as follows:
TableA    TableB
------   ------
1          3
2          4
3          5
4          6
Note that (1,2) are unique to TableA, (3,4) are common, and (5,6) are unique to TableB.
Inner join
An inner join using either of the equivalent queries gives the intersection of the two tables,
i.e. the two rows they have in common.
select * from a INNER JOIN b on a.a = b.b;
select a.*,b.*  from a,b where a.a = b.b;
TableA | TableB
------   ---+--
3      | 3
4      | 4
Left outer join
TableA left outer join will give all rows in TableA, plus any common rows in TableB.
select * from a LEFT OUTER JOIN b on a.a = b.b;
select a.*,b.*  from a,b where a.a = b.b(+);
TableA |  TableB
--     +-----
1      | null
2      | null
3      |    3
4      |    4
Full outer join
TableA full outer join will give you the union of TableA and TableB, i.e. All the rows
in TableA and all the rows in TableB. If something in TableA doesn't have a corresponding
data in TableB, then the TableB portion is null, and vice versa.
select * from TableA FULL OUTER JOIN TableB on a.a = b.b;
 TableA   |  TableB
-----     +-----
   1      | null
   2      | null
   3      |    3
   4      |    4
null      |    6
null      |    5




3 )   Query execution plan

Ans)

  • Query execution plan
    Sample Img 3
A query plan (or query execution plan) is an ordered set of steps used to access or
modify information in a SQL relational database management system.
There are typically a large number of alternative ways to execute a given query, with
widely varying performance. When a query is submitted to the database,the query optimizer
evaluates some of the different, correct possible plans for executing the query
and returns what it considers the best alternative.
Please take a look at the sample Query Execution Plan above for the following Query.
SELECT  header.[SalesOrderID] ,header.[OrderDate] ,header.[ShipDate] ,details.[ProductID]
,details.[OrderQty] ,details.[UnitPrice] ,header.[CustomerID] FROM
[Sales].[SalesOrderHeader] AS header JOIN [Sales].[SalesOrderDetail] AS details
ON header.[SalesOrderID] = details.[SalesOrderID] WHERE header.[CustomerID] = 29560;
If your application performamce is poor, this is one of the aspect you have to look at,
identify the time consuming Queries and review the execution plans of them and see
you could find an optimal one.



4 )   Select statement Sample

Ans)
Select distinct pub_id from titles order by type




5 )   Sample Delete

Ans)
delete authors where syb_identity = 4


6 )   Sample Update

Ans)
update salesdetail set discount = 40
        from salesdetail readpast
    where title_id like "BU1032"
        and qty > 100


7 )   Sample Cursor ?

Ans)
create procedure proc2 @flag int
as
if @flag > 0
    declare names_crsr cursor
    for select au_fname from authors

else
    declare names_crsr cursor
    for select au_lname from authors
return

8 )   DataBase Tigger ?

Ans)
A trigger executes automatically when a user attempts a specified data modification
statement on a specified table.
If the pub_id column of the publishers table is changed, make the corresponding
change in the titles table:
create trigger t2
on publishers
for update as
if update (pub_id) and @@rowcount = 1
begin
    update titles
    set titles.pub_id = inserted.pub_id
    from titles, deleted, inserted
    where deleted.pub_id = titles.pub_id
end



9 )   Drop And Alter

Ans)

Drop :
drop table otherdb..newtable

Alter :

alter table titles
    modify notes varchar(150) not null
    with exp_row_size = 40
alter table titles
    add author_type varchar(30) null
    modify city varchar(30)
    drop notes
    add sec_advance money default 1000 not null
    lock datarows
    with exp_row_size = 40


10 )   Sample query with Group By and Having ?

Ans)
group by
select type, avg(price) from titles group by type order by avg(price)
having
sets conditions for the group by clause, similar to the way in which where sets
conditions for the select clause. having search conditions can include aggregate
expressions; otherwise, having search conditions are identical to where search
conditions.
select pub_id, total = sum(total_sales)
from titles
where total_sales is not null
group by pub_id
having count(*)>5


11 )   java.lang.IncompatibleClassChangeError

Ans)
This Error occurs  when you compile a class with Different Version of JRE other than the one
 which this is being run(the Server on which you deploy this class files).
 For example, you compile a Java file by using Eclips which is using JRE 1.6, create a Jar file these class,
 and you deploy this Jar in a Env which is using JRE 1.4, this exception will be thrown.

Solution :


Please recompile this file with the correct version of JRE, in above case you have re-compile with JRE 1.4

"JavaScript "


Html/JavaScript related quick notes
1 )   Quick HTML Tags?

Ans)
Body Tag with onLoad Event :
<body onLoad="populateComboBox()"> </body>
Some other Events , onunload
HyperLink with OnClick Event :
<a href="http://testonClick="alert('You Clicked on HyperLink')">Visit your side</a>
Some Other Events,  onmousedown,onmousemove
Tooltip -  Use "alt" attribute for ToolTip
Input Text Box :
<input type="text" name="yourname" />
Text Area :
<textarea rows="2" cols="30">
 your First Text Are
</textarea>
Button with OnClick:
<button type="button" onClick='yourSubmit();'>Click </button>

 Or

 <input type="button" value="Click">
Submit Button :
<input type="submit" value="Submit" />
Reset Button :
<input type="reset" value="Reset" />
CheckBox :
<input type="checkbox" name="vehicle" value="Bike" checked />
Combo Box :
<select id='stateList' onchange='OnChange(this)'>
  <option value="NJ">New Jersy</option>
 </select>
Bullet List
 <ul >
         <li>First Bullet</li>
         <li>First Bullet</li>
 </ul>

 Div :
For invisible
 <div style="display: none;">
  <h2>Click Here</h2>
</div>
For Visble
 <div style="display: block;">
  <h2>Click Here</h2>
</div>



2 )   Form onLoad ()

Ans)
<html>
<head>
<script type="text/javascript">
function loadDropdown()
{
alert("Load Your Dropdown");
} 

</script>
</head>
<body onload="loadDropdown()"> 
<h1>Welcome to my Blog</h1>
</body>
</html>



3 )   Form onunLoad ()

Ans)
Same as above just use "onunLoad()"


4 )   Button Onclick

Ans)
<html>
<head>
<script type="text/javascript">
function yourSubmit()
{
alert("Submit Your Form");
} 

</script>
</head>
<body >
<h1>Welcome to Button OnClick Blog</h1>
<button type="button" onClick='yourSubmit();'>Click </button> 
</body>
</html>


5 )   Adding Options to HTML Dropdown

Ans)
Following Example Adds the States to States Dropdown
function addTheStates (dataArray,dataIDArray) {
//alert("addTheQuestions " + document.getElementById('questionList'));
 document.getElementById('statesList').options.length=0;
for (var i=0;i<dataArray.length;i++){
var option = document.createElement("option");
 option.setAttribute('value',dataIDArray[i]);
 option.innerHTML = dataArray[i];
 document.getElementById('statesList').appendChild(option);

 }
}

6 )   Get selected Item from a Dropdown?

Ans)
function getSelectedValue (dropdown1) {
    var myindex  = dropdown1.selectedIndex;
    var SelValue = dropdown1.options[myindex].value;

 alert(SelValue);
}
 


7 )   Clear HTML Text Boxes

Ans)
  function clearTextArea() {
      document.getElementById('yourTextBox').value='';
    }



8 )   Java Script Disable right Click ?

Ans)
<script language="JavaScript1.1">
<!--
var debug = true; function
right(e) { if (navigator.appName == 'Netscape' && (e.which == 3 || e.which
== 2)) return false; else if (navigator.appName == 'Microsoft Internet Explorer'
&& (event.button == 2 || event.button == 3)) { alert('This Page is fully
protected!'); return false; } return true; } document.onmousedown=right; if (document.layers)
window.captureEvents(Event.MOUSEDOWN); window.onmousedown=right;
//-->
    </script>


    9 )   Java ArrayList to JavaScript Array?

    Ans)
    function convertToArray () {
      var nfhEvents =new Array();
      <% ArrayList nfhList = (ArrayList)request.getAttribute("yourList"); 
      String[] stringArray = (String[])nfhList.toArray(new String[nfhList.size()]); 
      for (int i=0;i< stringArray.length;i++) { 
      %> nfhEvents[<%= i%>] = '<%= stringArray[i] %>'; 
      <% } %> 
      
      alert(nfhEvents);
      }



    10 )   Parse XML string by using Java Script ?

    Ans)
    unction xmlParser(questionName) {
                str = "<QuestionsList><Question>What is your    name?</Question><Answer>Smith</Answer><
                           /QuestionsList><QuestionsList><Question>Where you born ?</Question><Answer>Herndon</Answer></QuestionsList>";
             
                            var questionArray =new Array();
                    var xml = $.parseXML(str);
                    alert(xml.documentElement.nodeName);
                    i=0;
                    var result = $(xml).find("QuestionsList").each(
                    function(){  var question = $(this).find('Question').text();
                                            var name_text = $(this).find('Answer').text(); 
                                            questionArray[i] = img_path;
                                            i++;
                            }); 
                    alert(questionArray); 
              }



    11 )   Java Script Pop up window.

    Ans)
    window.open('<%=request.getContextPath()%>/web/less/tests/MiniArticles.jsp?questionId='+questionId,'MiniArticles',
    "menubar=1,resizable=1,scrollbars=1,width=800,height=610,");


    12 )   Java Script "Trim()" function

    Ans)
    Java Script "Trim()" function  
    function trim(str) {
    return str.replace(/^\s+|\s+$/g,"");
    }