Skip to content

Instantly share code, notes, and snippets.

@sapanparikh18
sapanparikh18 / _fields_boolean__wrapper.gsp
Last active January 3, 2016 09:40
Grails fields plugin wrapper customized to be compatible with materializecss. Each _wrapper or _widget files should go under views/_fields. For instance _fields_boolean__wrapper.gsp should go to views/_fields/boolean/_wrapper.gsp
<div class="row">
<div class="col l12">
<%= widget %>
<label for="${property}" data-error="wrong" data-success="right">${label}</label>
</div>
</div>
public static void runQuery(){ // This method does 3 things 1. Gets the db connection and 2. Runs the query 3. Closes the connection
Connection con = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection( "jdbc:mysql://localhost:3306/db","user","password");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from emp");
while(rs.next()) {
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
}
public static void runQuery(Connection connection){
try{
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from table");
while(rs.next()) {
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
}
}catch(Exception e){
//Handle exception
}
// 1.
int years = getYears(getDateOfBirth());
int months = getMonths(getDateOfBirth());
System.out.println("The age of the person is" + years + "years and "+months+" months");
// 2.
Date dob = getDateOfBirth();
int years = getYears(dob);
int months = getMonths(dob);
System.out.println("The age of the person is" + years + "years and "+months+" months");
//1.
for(User user:userList){
int year = getCurrentYear();
int days = getDaysInYear(year);
int dailySalary = user.getSalary()/days;
println "Daily salary of "+ user.getName() +" is "+dailySalary;
}
//2.
int year = getCurrentYear();
//...
refresh(){
if(invoicingFeatureEnabled){
Invoice.getInstance().refreshTaxes(this);
}
if(quotesAndProposolsEnabled){
QuotesAndProposols.getInstance().refreshTaxes();
}
if(salariesFeatureEnabled){
IncomeTax.getInstance().refreshTaxes(this);
import java.util.*;
public final class Broker {
private final Object mutex = new Object();
static class CommonTopics {
private CommonTopics() {
}
import java.util.HashMap;
import java.util.Map;
public class Invoice implements Subscriber {
@Override
public void update(Broker.Context ctx) {
System.out.println("tax rates changed");
}
refresh(){
Broker.getInstance().sendMessage(Broker.CommonTopics.ON_TAX_CHANGE,Collections.emptyMap());
}
public Reviewanswer getAnswer(int questionId) {
String sql = "select * from answers where questionid=:questionId";
Map<String, Object> params = new HashMap<>();
Reviewanswer answer = new Reviewanswer();
params.put("questionId",questionId);
try {
answer = namedParameterJdbcTemplate.queryForObject(sql,params,Reviewanswer.class);
}catch (DataAccessException ex){
Logger.getLogger(this.getClass().getName()).log(Level.ALL,ex.getLocalizedMessage());
}