Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Tuesday, December 8, 2015

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver when executing asterix-java AGI server

I implemented an asterisk-java AGI script with MySQL DB integration and tried to execute with following command

java -jar asterisk-java-1.0.0.M3.jar

Server started successfully and called successfully to the service abstract method. How when the call flow met with a scripting line related to DB operations I always got the following run-time error.

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
 
This error can be resolved mentioning the class-path for  

mysql-connector-java-5.1.9.jar

I tried several standard ways to start the AGI server with mentioned class-path for jdbc but failed. Finally I found the way through following answer.
http://stackoverflow.com/questions/8818073/classnotfoundexception-com-mysql-jdbc-driver

I successfully started the AGI server and executed DB related functions by starting the AGI server jar file as follows.

java -classpath asterisk-java-1.0.0.M3.jar:mysql-connector-java-5.1.9.jar:. org.asteriskjava.fastagi.DefaultAgiServer

(asterisk-java-1.0.0.M3.jar & mysql-connector-java-5.1.9.jar are in the same location)

Thursday, December 3, 2015

JAVA Get a random number within a value range

Following method can be used to get a random value which is within a minimum and maximum value range.

//Import following class
import java.util.Random;
 
//Custom method to get a random value 
public int getRandomNum(int maxVal, int minVal){
    Random rn = new Random();
    return rn.nextInt(maxVal - minVal + 1) + minVal;
} 

Sunday, March 30, 2014

A method to sort an primitive type array to descending order in JAVA

    public void sortDescending(double[]numbers){
        System.out.println("Array values in descending order ......");
        Double[] objDouble=new Double[11];
// Double object array initialization
       
        for(int counter=0;counter<11;counter++){
            objDouble[counter]=Double.valueOf(numbers[counter]);
// Converts the primitive type values of the primitive array into object type and assigning to the Double object array
        }
       
        Arrays.sort(objDouble,Collections.reverseOrder());
//Sort the Double object array
       
        for(Double nums:objDouble){
            System.out.println(nums);
        }

    }