Skip to main content

Posts

java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!

I got this exception while executing a HQL query using hibernate template. query is: select * from customer where id = :id and calling find() method. hibernate.find(mysql, new Object[]{123})  If  executing the query like namedQuery or createQuery this will be fine.  Since it is executing directly the query should be like this (? instead of parameter name) select * from customer wher id = ?

How to write Like query in hibernate?

There will be situation to write search query in hibernate using like keyword. SQL: select * from users where username like '%test%'; the above in hibernate query: "select u from User u where u.userName like :username" pass parameter as "%searchstring%" the code will look like: List<User> userList = getEntityManager().createQuery("select u from User u where u.userName like :username").setParameter("username", "%"+q+"%").getResultList();

How to see Android SDK logs?

In Android application can't use System.out.println(...);. Android have Log  to print some outputs while developing the application. This Log should be avoid in production. Log.v("TAG", "MSG") - Verbose Log.e("TAG", "MSG") - Error Log.d("TAG", "MSG") - Debug These logs can't be seen in eclipse or any other place. These logs can be viewed only adb shell. $adb shell # logcat

Android development environment on Windows

Before start installing SDK make  sure system have JDK 5 or later. Download Android SDK installer for windows and install from here  http://developer.android.com/sdk/index.html After installed run the android SDK and atleast one SDK platform example (2.3.3) Open eclipse and go to "Install New Software" Install ADT plugins from https : //dl-ssl.google.com/android/eclipse/ restart the eclipse In Eclipse, Open Window -> Preferences and select "Android" from left side Select the path of the Android SDK installed In Eclipse, Open Window -> Android SDK and AVD manager. From SDK manager, can install required android platforms, libraries and etc... That's All, we are good to start Android application development. This is best startup giude  http://developer.android.com/resources/tutorials/hello-world.html

Android development in Linux (Ubuntu)

Setting up Android development environment in Linux is very easy compare to windows. :( Before start make sure system have JDK5 or latest version of Java. JRE is not enough JDK needed. Install Android SDK. (just extract linux version SDK zip file to a folder) Install eclipse:  sudo apt-get install eclipse In Eclipse, Open  "Install New Software" add Ecplise ADT plugin  https : //dl-ssl.google.com/android/eclipse/ After installed ADT plugin, restart the eclipse. In Eclipse, Window -> Preferences, Select Android on left side. Choose the path of the Android SDK installed folder. Click OK. In Eclipse, Window -> Android SDK and AVD Manager Install the platforms, samples and compatibility library from there.  That's all we are good to start develop Android Applications..... This is best startup giude  http://developer.android.com/resources/tutorials/hello-world.html

PHP file upload permission in linux

Normally while upload a file and move that file into web folder, will throw a error.  Moving uploaded file will work fine in windows. PHP Warning:  move_uploaded_file(upload/<<filename>>): failed to open stream: Permission denied in /var/www/<<project>>/some.php on line 21, referer: http://localhost/project/some.php To solve above problem. change permission to 077 to that upload folder. user@system:/var/www/project$ chmod 077 upload/

Prevent SQL injection in PHP with MySQL

SQL injection is more vulnerable in web applications. When using PHP with MySQL avoiding SQL injection is very simple.  The below code is not safe. Because once can inject own sql command here. like " 1; delete from customer where customerid = '1' ;" will delete the customer from table. $customerId = $_GET["cid"]; $sql = "select * from customer where customerid = $customerId"; There is built-in function to prevent SQL Injection from MySQL library. Before passing the parameter to SQL, make the parameter as safe by calling this function like below. $customerId =  mysql_escape_string( $customerId); $sql = "select * from cutomer where cutomerid = $customerId";