Thursday, January 30, 2014

Ping failed Exception - Class name is wrong or classpath is not set for : com.mysql.jdbc.jdbc2.optional.MysqlDataSource Please check the server.log for more details.

You are surely getting this when trying to create a connection pool in glassfish. The reason is that the jar file of mysql database is missing. In order to solve it if don't already have the mysql connector you may get one from here and add it to the following location under your glassfish directory:
C:\glassfishv3xxx\glassfish\domains\domainxxx\lib\ext

Restart your glassfish server and access the admin console. Hopefully from now on you will be able to ping your pool successfully.

It is also important to note that  Ping failed Exception - Class name is wrong or classpath is not set for : error is applicable to other database. You can solve it as mentioned earlier by downloading the corresponding jar of the given database.

Location of Jars in glassfish

When dealing with web application requiring database, you can easily get stuck during the connection pool in glassfish because of your specific database jars. After the creation of each new domain in glassfish the jars location is under:

C:\glassfishv3xxx\glassfish\domains\domainxxx\lib\ext

Location of Jars in ireport

Many tend to be confused about the location of  jars libraries in jasper ireport. In fact for the case of Microsoft Windows, after the installation yours jars will reside inside the following location:

C:\Program Files\Jaspersoft\iReport-XXX\ireport\modules\ext


Saturday, January 25, 2014

ORA-12519: TNS:no appropriate service handler found

Who does not like oracle ? Of course everyone does, however problems arise when you run into trouble. Luckily that oracle make easier for us to trace errors by always assigning to them a specific number ORA-XXXXX. In line with that here is another common error message ORA-12519....:
The root cause of this error message is   the low PROCESSES initialization parameter value. In fact  the PROCESS parameter describes the total number of operating system process allowed to access the database concurrently.
                                          This total process is divided into user process and background processes, user processes are the processes allotted to the users connected to the database and the background processes are the processes utilized by the database.

Solution outline:  Increase the number of PROCESSES parameter value.
How: Try to login as a user with at least a  SYS privilege.
sql> alter system set processes=300 scope=spfile;
sql> shutdown immediate;
sql> startup;

Feel free to drop a comment.
 
 

Thursday, January 16, 2014

Oracle to Mysql migration

When comes the time to migrate data from Oracle to Mysql especially if you are on production, many questions usually arise. If you even try to google it many folks out there will suggest this and that tools. Often many of those tools are not even free. So far I have successfully perform this migration on production with ease using only the Mysql Workbench. Believe me this tool is awesome and easy to use. In this post I will not even bother about showing you some screen shots, just try it and you will feel what I mean.
 And as I mention earlier there is no need to spend a penny to buy any other so called special tool out there. It is not only supporting Oracle alone but other different RDBMS too.
Feel free to drop a comment to share your experience too.

Monday, January 13, 2014

Best tutorial for Django

I know this is apparently a hot topic that may raise a lot of discussion, however having wasted a substantial amount of my time trying and searching the best doc to get started with django framework I came to this conclusion. The Django Book is the most comprehensive place to get get started with    Django.       Being online it is  regularly updated compared to other books  you may have out there.
That said you are warned, don't go waste your precious time out there trying to find NOTHING.
You can easily use the scrapbook addon of firefox to download the entire website and read it offline.
You too if you have found something better please don't hesitate to share it  with us...

Offline website reader

I just discover this firefox addons reader that recently and since then decided to write this small post about it. It is named: SCRAPBOOK  In fact it downloads an entire website and save it in your PC. Not only can you decide the depth , it also has many more options that you may easily explore from its web page. There is a small video tutorial  of less than 2 minute on youtube for to easily get started.

Django admin page without style

Yep if you have into this mess


and now wondering how to restyle your fancy admin page, cool down it very simple. Just go to the settings.py file and make sure that you have enable this apps:

'django.contrib.staticfiles',

you may then have

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'books',
)

Friday, January 10, 2014

Currency data type in Java, Mysql and Oracle

Initially I had no intention of writing this post till I saw a friend of mind in a total mess. When dealing with financial applications data type is a key thing to be careful with. So far I have written many financial applications especially for accounts using java, mysql and oracle and would like to share my experience with you. I won't talk much because I am pragmatic and like going straight to the point.

Java: BigDecimal
Mysql: NUMBER (19,2) 
OracleNUMBER (19,2)
Exchange rate: NUMBER (19,4)
Rounding: .setScale(2,RoundingMode.HALF_EVEN) 

If you have been around this for a while the above five lines will be your key to heaven.
Don't hesitate to throw some comments.

 

View and kill process from Windows command line

How can you view and kill a process from the command line ?
First you need to know the process id (PID). Check from the task manager as show below

For example here my ireport program has a pid = 5880.

Second, you may directly get it from the command by typing the following in the cmd:
cmd> netstat -ona
 
Three, now comes the time to kill our process.
cmd> taskkill /pid 5880

 If it persists you can force it with a force option ( /F )
 cmd> taskkill /F /pid 5880

You may also search from cmd as follow:
cmd> netstat -ona | find ":80"
cmd>netstat -ona | find "LISTENING"
cmd>netstat -ona | find ":80"  | find  "ESTABLISHED"
and so forth.

Reset glassfish password SOLVED

Have forgotten your admin credential or mess out with your server and trying to log in without success ?
To reset your password here is how you will do it.
1. Solution ONE:
 Open your admin-keyfile located in C:\glassfishv3\glassfish\domains\domain1\config (C: or domain1 may be different, glassfishv[VERSION]).

replace the content with:

anonymous;{SSHA}WQVj8i9CLECCiv+w6ZxGgMrcfPqHPoXZW+2Jdw==;asadmin

# Domain User and Password - Do Not Delete Entry Above

Then restart your server !!!

2. Solution TWO:
In order to get a new admin-keyfile we will create a new domain, then copy it into our existing server.

Right your glassfish server :

Then add a new glassfish server
Then server name

then NEXT
Then domain name: domain2 , Finish button activates. Finish
Successfull message

Congratulation your new server with new domain name domain2 is created.

Now  copy this file admin-keyfile located in C:\glassfishv3\glassfish\domains\domain2\config
 (C: or domain1 may be different, glassfishv[VERSION]).

Replace the admin-keyfile of domain1 of with the new one from domain2.

Restart your server and enjoy !!!

3. Solution THREE:
    As there never a two without three, here is another simple way of creating a new domain in order to obtain a new admin-keyfile for replacing the old one in our domain1. This time around we use the command line.
  Go to the cmd and locate your glassfish installation directory.
   cd C:\glassfishv3\bin
 C:\glassfishv3\bin>asadmin create-domain --savemasterpassword domain2
 Please just type enter to accept the default username and password !!!
After copying the newly created admin-keyfile in  C:\glassfishv3\glassfish\domains\domain2\config
You may delete the new domain domain2. Using the following command.
 C:\glassfishv3\bin>asadmin delete-domain domain2
and so was it!!!

Getting a org.springframework.beans.factory.BeanCreationException with my first Maven, Spring Project

If you are getting this error message, you maybe missing a crucial jar file in your project. Just download the spring- jar include it to your project, build it and move forward.

Caused by: java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser

Facing this problem can be very painful, I have been and lost a couple of my precious hours trying to dig it out. I won't talk much because it is not my field of predilection. I am pragmatic and let us go straight to the point.
Solution:
You have download two jars and include in your project.
  1. commons-javaflow
  2. spring- jar
Hopefully you have include them, build your project and regain your smiling face. Happy coding day though  !!!

Wednesday, January 8, 2014

Conditional expression in ireport

Expression condition for the first in ireport for many usually seems awkward given that we have to leave behind our programming legacy of  IF ELSE and do it another way.

And here come the issue, suppose we have to define the following condition :

IF boolean condition THEN
 
     execute true code snippet
 
 ELSE
 
    execute false code snippet
 
 END IF
 
Ireport we will otherwise do it as follow:
 
 
( boolean condition ? execute true code snippet : execute false code snippet)
 
e.g:
 
if ( conVar > 0 )
     binVar= 1
 
else binVar= -1
 
Then becomes:
 
 (conVar > 0 ? binVar= 1: binVar=-1)

 
It the similar way we can express some complicated and nested conditions.
If you still face any problems feel free to drop a comment. 

Tuesday, January 7, 2014

django administration: You don't have permission to edit anything.

Yep! it seems you are locked out of your own application. Is this how django treats its followers ?
Trust me Django is right, because after it is for your own good against the www attacks.

This is a minor issue just good to ursl.py and add the following line:
admin.autodiscover()

Finally your urls.py will look ask follow:
from django.conf.urls import patterns, include, url
from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'mysite.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),

    url(r'^admin/', include(admin.site.urls)),
)
Happy coding !!!

Monday, January 6, 2014

unexpected keyword argument 'maxlength' in Django

This problem arise because you are using the latest version of django. Just replace maxlength with max_length.  If you really want to keep using maxlength you must downgrade to django .96.
I hope it removes your road block, have a safe coding journey. See you next time...

python manage.py validate no module named image error

Are you victim of Django ImageField from your model declaration and keep getting "no module named image error" ? Ok, chances are that you have not installed the PIL or  python image library.

Just download and install the latest version and keep rocking. 

Cast string to integer in mysql

So you want to convert an attribute with string (varchar) type to a number (integer) in your mysql query ?
If you have enough time have a look here, otherwise just blindly follow the following example.
  Suppose you have some code 002, 007, 001 that you want to be 2, 7, 1.
SELECT  CAST(CODE AS UNSIGNED) FROM MY_TABLE;
 The same scenerio may be repeated with other types, it that case
  the type for the result can be one of the following values:
  • BINARY[(N)]
  • CHAR[(N)]
  • DATE
  • DATETIME
  • DECIMAL[(M[,D])]
  • SIGNED [INTEGER]
  • TIME
  • UNSIGNED [INTEGER]
 So far so good, isn't it ?

Sunday, January 5, 2014

ImproperlyConfigured: Requested setting TEMPLATE_DEBUG, but settings are not configured.

Maybe you want to test your first django template but keep getting this annoying error message. You certainly getting this error because you are misusing the shell. You are using python shell instead of a django managed shell. Saying this, what do i really mean. Suppose you want to test the following template:
>>> from django.template import Context, Template
>>> t = Template("Hello {{ name }}.")
>>> c = Context({"name": "World"})
>>> t.render(c)
Instead of running the above script from the python shell, go the command prompt ( if you are using winodws os)

cmd>django-admin.py startproject dummyProject
cmd> cd dummyProject
dummyProject> python manage.py shell
>>> 
>>> from django.template import Context, Template
>>> t = Template("Hello {{ name }}.")
>>> c = Context({"name": "World !"})
>>> t.render(c)
Hello World !

Congratulation , you just run your first django template.

Saturday, January 4, 2014

Sqlite3 installation on windows

So you want to install sqlite3 and wonder how to do so because there is no single executable file to click on and follow up ?
No problem just go to sqlite3 download page  and under the Precompiled Binaries for Windows part, download the following three file and unzip them.
-sqlite-shell-win32-x86-xxx.zip
-sqlite-dll-win32-x86-xxx.zip
-sqlite-analyzer-win32-x86-xxx.zip


Then after unzipping them put, paste the unzipped files in C:\windows\System32

That is all, now from your command prompt terminal (CMD) type: sqllite3 and your are in.
sqlite>.help

Installing Django on Windows 7 in less than 5 minutes

Out there, there are many tutorials but I think this one may just make the differece.
I assume that you have downloaded a python 2.7.x  and copy of Django 1.6.x .I also suppose that you are familiar with cmd commands like cd, dir , cd.., etc

Step ONE: Install Python
Click on the Python just downloaded to launch the installation. Just follow next and all the defaults.
It should be installed in C:\python27.

Step TWO: Make Python available in the terminal (cmd):
To do this you have to register it as system variables.
Right-Click Properties --> Advanced system settings -->Environment Variables -->System variable -->path -->Edit: and paste the following.
;C:\Python27;C:\Python27\Scripts;C:\Python27\DLLs\;C:\Python27\Lib\;

Step THREE: install Django
Unzip the downloaded compressed folder under the C: drive.
Go to the Command prompt CMD and navigate inside the C:\Django 1.6.x folder.
> cd C:\Django 1.6.x
 C:\Django 1.6.x> python.exe setup.py install 
Please wait till all is done. 

Step FOUR: Create a Django Project Go to a location where you want to create your project. Our project name is ido.

cmd ..> django-admin.py startproject ido
 ..ido> python.exe manage.py runserver

Step FIVE: Launch it.
 Just open your browser and type:
 http://127.0.0.1:8000

By now you should have your project available. Feel free to amend.

Friday, January 3, 2014

OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")

I came across this disgusting  error message while try to connect to mysql in python 2.7.
In fact I wrote something like :
import MySQLdb
db = MySQLdb.connect(host="localhost", user="py", passwd="py", db="test")

You can get rid of the above mentioned error by just replacing the host: localhost by 120.0.0.1

import MySQLdb
db = MySQLdb.connect(host="127.0.0.1", user="py", passwd="py", db="test")
...

Disable autocomplete in JSF

Are you fed up with autocomplete in JSF and want to disable it at all costs ?
<h:inputText value="#{myBean.name}" autocomplete="off"/>
Just refresh your page and move on.

Writing NamedQuery with like in where clause

Undoubtedly that you are reading this post because you have run into the trouble with your sql queries especially if like me you are a fervent adept of Sql. But don't panic it is more simpler than you may have thought to do it. Let say for example that your initial sql query looks like the following:
SELECT * FROM school v where v.country like 'CA%';
Now  the named query in your entity bean should be:

        @NamedQuery(name = "School.findByCountry", query = "SELECT v FROM School v WHERE (  v.country LIKE :country)")

Finally we confidently call our named query as follows:
               String pattern= "CA"
    em.createNamedQuery("School.findByCountry")
                 .setParameter("country",   pattern+"%")
                 .getResultList();
Hoping you have gained back your  usual sql honey moon time. Don't forget to drop your comment...

Thursday, January 2, 2014

Collection data types in Python: Sequence vs Sets vs Mappings

No matter what some folks will argue or say, understanding key differences between python collection  data types is essential to pave your way from much headaches. I got this important explanation from this book . In fact in python or even other similar programming languages we have three types of Collection data types : Sequences, sets and mappings.

Sequences:  A sequence type is one that supports the membership operator (in), the sizefunction (len()), slices ([]), and is iterable. Python provides five built-in sequence types: bytearray, bytes, list, str, and tuple:
  •  Tuples: A tuple is an ordered sequence of zero or more object references. It supports the same slicing and striding syntax as  strings.Like strings, tuples are immutable, so we cannot replace or delete any of their items. If we want to be able to modify an ordered sequence, we simply use a list instead of a tuple; or if we already have a tuple but want to modify it, we can convert it to a list using the list() conversion function and then apply the changes to the resultant list.   e.g: myTyple= 'soulemane', 'cse', 2014, -1, 'y'
  • Lists: A list is an ordered sequence of zero or more object references. Lists support the same slicing and striding syntax as strings and tuples. This makes it easy to extract items from a list. Unlike strings and tuples, lists are mutable, so we can replace and delete any of their items. It is also possible to insert, replace,and delete slices of lists.
e.g:  myList= ['soulemane', 'cse', 2014, -1, 'y']


Sets: A set type is a collection data type that supports the membership operator (in), the size function (len()), and is iterable.Python provides two built-in set types: the mutable set type and the immutable frozenset. When iterated, set types provide their items in an arbitrary order.
      All the built-in immutable data types, such as float, frozenset, int, str, and tuple, are hashable and
can be added to sets. The built-in mutable data types, such as dict, list, and set, are not hashable since
their hash value changes depending on the items they contain, so they cannot be added to sets.
  •  Sets: A set is an unordered collection of zero or more object references that refer tohashable objects. Sets are mutable, so we can easily add or remove items, but since they are unordered they have no notion of index position and so cannotbe sliced or strided.
e.g:  myList= {'soulemane', ('cse', 2014), -1, 'y'}
  • Frozen Sets: A frozen set is a set that, once created, cannot be changed. We can of course rebind the variable that refers to a frozen set to refer to something else, though. Frozen sets can only be created using the frozenset data type called as a function.  Since frozen sets are immutable, they support only those methods and operators that produce a result without affecting the frozen set or sets to which they are applied.
Mappings:  A mapping type is one that supports the membership operator (in) and the size function (len()), and is iterable. Mappings are collections of key–value items and provide methods for accessing items and their keys and values. When iterated, unordered mapping types provide their items in an arbitrary order.  
         Only hashable objects may be used as dictionary keys, so immutable data types such as float, frozenset, int, str, and tuple can be used as dictionary keys, but mutable types such as dict, list, and set cannot. On the other hand, each key’s associated value can be an object reference referring to an object of any type, including numbers, strings, lists, sets, dictionaries, functions, and so on.
  • Dictionaries: A dict is an unordered collection of zero or more key–value pairs whose keys are object references that refer to hashable objects,and whose values are object references referring to objects of any type. Dictionaries are mutable, so we can easily add or remove items, but since they are unordered they have no notion of index position and so cannot be sliced or strided.
e.g: myDict = dict({"Nb": 2014, "soulemane": "moumie", "salary": 10})
                  or
    myDict = {"Nb": 2014, "soulemane": "moumie", "salary": 10}

One important remarks is to notice maps or dictionary are defined with braces {} with each key-value pair element separated with a colon ,  sets are defined with braces {}, lists are defined with brackets [] ,  and tuples are directly and openly defined.