SQL – Find all tables in the MS SQL Server DataBase that are missing specific column
Example SQL select, that lists all tables in the database, which are missing some specific column ( in this example – column named ‘myColumn’.
select t.TABLE_CATALOG, t.TABLE_NAME, c.COLUMN_NAME from INFORMATION_SCHEMA.TABLES t left outer join INFORMATION_SCHEMA.COLUMNS c on t.TABLE_NAME = c.TABLE_NAME and c.COLUMN_NAME = 'myColumn' and c.COLUMN_NAME is null
SQL – Find all tables in the MS SQL Server DataBase with searched column
select t.TABLE_CATALOG, t.TABLE_NAME, c.COLUMN_NAME, c.IS_NULLABLE, c.DATA_TYPE from INFORMATION_SCHEMA.TABLES t
Simple sql select, which result contains all tables in the database, that have specific, searched column.
This example lists all tables that have column named ‘myColumn’.
select t.TABLE_CATALOG, t.TABLE_NAME, c.COLUMN_NAME, c.IS_NULLABLE, c.DATA_TYPE from INFORMATION_SCHEMA.TABLES t
inner join INFORMATION_SCHEMA.COLUMNS c on t.TABLE_NAME = c.TABLE_NAME and c.COLUMN_NAME = ‘myColumn’
JavaScript – compare two dates, validate date range
function validateDateRange(date1Id, date2tId, errMsg){
date1 = document.getElementById(date1Id).value;
date2 = document.getElementById(date2Id).value;
//alert(date1 + ‘<>’ + date2);
if(date1 != null && date2 != null){
if (Date.parse(date1) > Date.parse(date2)) {
document.getElementById(date2Id).value = date1;
alert(errMsg);
return false;
}
}
return true;
}
Get values using parameter passing with JSF and AJAX
EXAMPLE JSP:
<!DOCTYPE html PUBLIC „-//W3C//DTD HTML 4.01 Transitional//EN“ „http://www.w3.org/TR/html4/loose.dtd“>
<%– jsf:pagecode language=“java“ location=“/src/pagecode/cpc/jsf/bp/contextFilters/CtxFilterDocuments.java“ –%><%– /jsf:pagecode –%><%@ page
language=“java“ contentType=“text/html; charset=UTF-8″
pageEncoding=“UTF-8″%><%@ taglib prefix=“f“
uri=“http://java.sun.com/jsf/core“%>
<%@ taglib prefix=“h“ uri=“http://java.sun.com/jsf/html“%>
<%@taglib uri=“http://www.ibm.com/jsf/html_extended“ prefix=“hx“%><html>
<head>
<meta http-equiv=“Content-Type“ content=“text/html; charset=UTF-8″>
<title>Insert title here</title>
</head>
<hx:scriptCollector id=“scCtxFDocs“>
<f:subview id=“svCtxFDocs“>
<hx:panelBox styleClass=“panelBox“ id=“boxCtxFilterDocs“
layout=“pageDirection“ border=“0″ cellpadding=“0″ cellspacing=“0″>
<hx:panelBox styleClass=“panelBox“ id=“boxDocCriteria“
layout=“lineDirection“ align=“left“ valign=“top“ cellpadding=“0″
cellspacing=“0″>
<h:panelGrid columns=“1″>
<h:outputText styleClass=“outputText“ value=“Reg. ID“></h:outputText>
<h:inputText styleClass=“inputText“ id=“prmDocsRegId“></h:inputText>
</h:panelGrid>
<h:panelGrid columns=“1″>
<h:outputText styleClass=“outputText“ value=“Reg. Num“></h:outputText>
<h:inputText styleClass=“inputText“ id=“prmDocsRegNum“></h:inputText>
</h:panelGrid>
</hx:panelBox>
<hx:ajaxRefreshRequest target=“boxDocsResults“ id=“arrboxDocsResults“
params=“prmDocsRegId;prmDocsRegNum“></hx:ajaxRefreshRequest>
<hx:panelBox styleClass=“panelBox“ id=“boxDocsButtons“
layout=“lineDirection“ cellpadding=“0″ cellspacing=“0″>
<hx:commandExButton type=“button“ value=“Търси“
styleClass=“commandExButton“ id=“btnSearchDocsDialog“>
<hx:behavior event=“onclick“ behaviorAction=“get“
id=“bhv_btnSearchDocsDialog“ targetAction=“boxDocsResults“></hx:behavior>
</hx:commandExButton>
</hx:panelBox>
<hx:panelBox styleClass=“panelBox“ id=“boxDocsResults“ border=“0″
layout=“pageDirection“ cellpadding=“0″ cellspacing=“0″>
<h:outputText id=“prm1Label“ value=“prmDocsRegId value“ />
<h:outputText id=“prm1″ value=“#{mBResults.prm1}“ />
<h:outputText id=“prm1Label“ value=“prmDocsRegNum value“ />
<h:outputText id=“prm2″ value=“#{mBResults.prm2}“ />
</hx:panelBox>
</hx:panelBox>
</f:subview>
</hx:scriptCollector>
</html>
JAVA CLASS:
public class MBSearchedResults{
Map<String, String> ctxMap;
private String prm1;
private String prm2;
public MBSearchedResults() {
super();
this.ctxMap = FacesContext.getCurrentInstance().getExternalContext()
.getRequestParameterMap();
}
public String getPrm1(){
// Взимаме си параметрите
String pprmDocsRegId = this.ctxMap.get(„prmDocsRegId“);
if (pprmDocsRegId != null) {
this.prm1 = pprmDocsRegId;
}
return this.prm1;
}
public String getPrm2(){
String pprmDocsRegNum = this.ctxMap.get(„prmDocsRegNum“);
if (pprmDocsRegNum != null) {
this.prm2 = pprmDocsRegNum;
}
return this.prm2;
}
}
Java – Another enumeration example
public enum EnumRefValues {
ref_type_1(„sysNameRefType1″, „name1″),
ref_type_2(„sysNameRefType2″, „name2″),
ref_type_3(„sysNameRefType3″, „name3″);
private String sysName;
private String name;
private MapNomValues(String sysName, String name) {
this.sysName = sysName;
this.name = name;
}
private MapNomValues(String value) {
this.sysName = value;
}
public String getSysName() {
return this.sysName;
}
public String getName() {
return this.name;
}
}
Results:
ref_type_1.getName(); returns -> name1
ref_type_1.getSysName(); returns -> sysNameRefType1
Java – Clone objects – example
For objects cloning, you can use java.lang.Cloneable. It is not applicable for deep cloning (for deep cloning use Serialization), because you should control the overall clone process, but it works for simple cloning in most cases.
To use clone() method, you should implement java.lang.Cloneable and override clone(), because it is not visible. There is an example:
public abstract class Criteria implements Cloneable {
Criteria() {
super();
}
@Override
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
return null;
}
}
}
Java – Scanner example
package com.xxxxx.tests;
import java.util.Scanner;
public class ScannerExample{
/**
* @param args
*/
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.println(„Write smthng: „);
String a = scan.next();
System.out.println(„Smthng: “ + a);
}
}
JSF – IBM DatePicker, choose first day of the week – example
Ако искате първият ден от седмицата в календара ви да е понеделник просто трябва да добавите /firstDay=“1″/.
<h:inputText id=“calExample“
styleClass=“inputText“
value=“#{mBean.dateRealBegin}“>
<hx:convertDateTime pattern=“#{mBean.dateFormat}“ />
<hx:inputHelperDatePicker id=“calExampleDatePicker“ firstDay=“1″ />
</h:inputText>