Wednesday, August 31, 2016

Show error on grails domain class

When saving the a domain class and the data is not saved to the database, we can trace with this code :


if (!myDomainObj.save()) {
   log.warn myDomainObj.errors.allErrors.join(' \n') //each error is an instance of  org.springframework.validation.FieldError    
}

reference : http://stackoverflow.com/questions/4765037/why-doesnt-grails-notify-me-of-error-at-domain-object-saving

Tuesday, March 15, 2016

Java SQL : Query with paramater

I use this class to run sql query with parameter


/* @author adam_crume
*/
public class NamedParameterStatement {
    /** The statement this object is wrapping. */
    private final PreparedStatement statement;

    /** Maps parameter names to arrays of ints which are the parameter indices. 
*/
    private final Map indexMap;


    /**
     * Creates a NamedParameterStatement.  Wraps a call to
     * c.{@link Connection#prepareStatement(java.lang.String) 
prepareStatement}.
     * @param connection the database connection
     * @param query      the parameterized query
     * @throws SQLException if the statement could not be created
     */
    public NamedParameterStatement(Connection connection, String query) throws 
SQLException {
        indexMap=new HashMap();
        String parsedQuery=parse(query, indexMap);
        statement=connection.prepareStatement(parsedQuery);
    }


    /**
     * Parses a query with named parameters.  The parameter-index mappings are 
put into the map, and the
     * parsed query is returned.  DO NOT CALL FROM CLIENT CODE.  This 
method is non-private so JUnit code can
     * test it.
     * @param query    query to parse
     * @param paramMap map to hold parameter-index mappings
     * @return the parsed query
     */
    static final String parse(String query, Map paramMap) {
        // I was originally using regular expressions, but they didn't work well for ignoring
        // parameter-like strings inside quotes.
        int length=query.length();
        StringBuffer parsedQuery=new StringBuffer(length);
        boolean inSingleQuote=false;
        boolean inDoubleQuote=false;
        int index=1;

        for(int i=0;i





example to use this class : 





...
                NamedParameterStatement p = new NamedParameterStatement(tempConn, "SELECT username, password FROM username WHERE username = :paramUsername");
                p.setString("paramUsername", txtUsername.getText());
                ResultSet tempRs = p.executeQuery();
...

Reference : http://www.javaworld.com/article/2077706/core-java/named-parameters-for-preparedstatement.html

Wednesday, January 27, 2016

VB6 Compatibility Issue on Windows 7

My project it using VB6 and ADO. When I compile the project on Windows 7 machine, the generated application (.exe file) is working well on other Windows 7 machine. But then error when its running on Windows XP machine.

Solution: download Windows6.1-KB2640696-v3-x86.msu from microsoft website. Then install this update package on developer machine (on my Windows 7 machine) and recompile the project

reference: https://support.microsoft.com/en-us/kb/2640696

Thursday, November 5, 2015

Linux command low level format

Warning!!! This command will destroy all data on your drive

This command is use to check bad sector on a hard disk.

dd if=/dev/zero of=/dev/sda1 bs=1024



Now we know that is a trouble at first 1 GB

Monday, August 10, 2015

How to check data chanel and info chanel (MikroTik + USB Modem / 3G Modem)

[admin@MikroTik] > /system serial-terminal usb2 channel=2

[Ctrl-A is the prefix key]


ATI
Manufacturer: Option N.V.
Model: GTM378
Revision: 2.3.3Hd (Date: Jul 17 2007, Time: 15:49:23)

OK

reference : http://wiki.mikrotik.com/wiki/Option_Globetrotter_HSDPA_USB_Modem

Tuesday, July 14, 2015

Windows server boot problem



I got this error after restore windows server 2008 using clonezilla. To fix it, boot to Windows Server 2008 DVD, enter command line, use this command :


bootrec /scanos

Bcdedit /export C:\BCDBkp

ren c:\boot\bcd bcd.old

Bootrec /rebuildbcd



Reference :

Monday, June 29, 2015

Replacing hard disk on xenserver / linux software RAID

mark as failed disk :

    mdadm --manage /dev/md0 --fail /dev/sdb1 

remove the disk :

    mdadm --manage /dev/md0 --remove /dev/sdb1


change the physical drive, copy the partition, create the exact same partitioning as on/dev/sda :
    sfdisk -d /dev/sda | sfdisk /dev/sdb


add the new drive
    mdadm --manage /dev/md0 --add /dev/sdb1


done, check the progress :
    cat /etc/mdstat



references: