(Ganesh Tiwari) gt_ebuddy's Blog - Code snippets, technical articles, tips on computing and programming...
Grails - beginners video tutorial
From the Grails site: "Grails aims to bring the 'coding by convention' paradigm to Groovy. It's an open-source web application framework that leverages the Groovy language and complements Java Web development. You can use Grails as a standalone development environment that hides all configuration details or integrate your Java business logic. Grails aims to make development as simple as possible and hence should appeal to a wide range of developers not just those from the Java community."
grails- add jar to lib folder - not working - solution
In grails application you can add jar dependencies by just pasting the .jar file to lib folder. If your code doesn't find the jar dependency at runtime then you can do following :
Right Click on project -> Grail Tools -> Open Grails Command Prompt
Hope this helps.
Run the following grail command (s):
In eclipse you can open the Grails Command Prompt by :- clean
- compile --refresh-dependencies
Right Click on project -> Grail Tools -> Open Grails Command Prompt
Hope this helps.
nepali english date conversion logic - working java code
I just found someone has blogged about Nepali-English date conversion in this post:
http://forjavaprogrammers.blogspot.com/2012/06/how-to-convert-english-date-to-nepali.html
He has explained the algorithm in detail about how to convert English dates into Nepali dates with java code.
java spring - read properties file variable from xml -PropertyPlaceholderConfigurer
Java springframework xml configuration file - how to read properties file variables from spring xml :
We have to use PropertyPlaceholderConfigurer bean for this.
We have to use PropertyPlaceholderConfigurer bean for this.
1).properties file location -
- src/main/resource @ maven managed project
- OR at classpath
2)The xml code to initialize/read properties file,
hibernate annotation inheritance mappedsuperclass - common columns in super class
When you are using annotations for hibernate object relational mapping, there might be the case that we need to abstract out some common columns that goes into all table definitions. These columns might be ID, DFlag, LastModifiedDate etc..
In such case we can take advantage of @MappedSuperclass annotation to achieve inheritance in hibernate annotation.
Example :
It works !
In such case we can take advantage of @MappedSuperclass annotation to achieve inheritance in hibernate annotation.
Example :
Super class BaseTable that contains common column definitions:
@MappedSuperclass
public abstract class BaseTable {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "dflag")
private int dFlag;
@Column(name = "lastmodifieddate")
private Date lastModifiedDate;
//other required columns
....
}
Extending it to use in other tables :
@Entity
@Table(name = "LoginUser")
public class LoginUser extends BaseTable implements Serializable{
private static final long serialVersionUID = -1920053571118011085L;
@Column(name = "username")
private String username;
@Column(name = "password")
private String password;
@Column(name = "invalidCount")
private int invalidCount;
//other required tables
...
}
It works !
mysql hibernate unicode support - character set, collate
I just did following configurations to achieve Unicode support in my Java+Hibernate+MySQL project.
Configuring MySQL to support Unicode - set Character Set and Collate as :
Hibernate JDBC connection string :
Hibernate Configuration:
Configuring MySQL to support Unicode - set Character Set and Collate as :
CREATE TABLE YOUR_DB_NAME
CHARACTER SET "UTF8"
COLLATE "utf8_general_ci";
NOTE : You Need to do "ALTER TABLE" instead of "CREATE TABLE",
if you are going to modify existing DB.
Hibernate JDBC connection string :
jdbc.url=jdbc:mysql://localhost:3306/YOUR_DB_NAME?useUnicode=true&characterEncoding=UTF-8
Hibernate Configuration:
<hibernate-configuration>
<session-factory>
...
<property name="hibernate.connection.charSet">UTF-8</property>
<property name="hibernate.connection.characterEncoding">UTF-8</property>
<property name="hibernate.connection.useUnicode">true</property>
...
</session-factory>
</hibernate-configuration>
Java code to find public IP address (servlet and client side code)
Java code to find public IP address :
URL url= new URL("http://gt-tests.appspot.com/ip");
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String ip = in.readLine();
System.out.println("IP : "+ip);
I created a simple servlet app on google app engine and posted at http://gt-tests.appspot.com/ip .
The servlet code returns the public address of client, it looks like :
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
PrintWriter out = resp.getWriter();
// Get client's IP address
String addr = req.getRemoteAddr();
out.println(addr);
...
Subscribe to:
Posts (Atom)