Forum: Building VoltDB Applications

Post: Error in compiling ddl.Sql

Error in compiling ddl.Sql
Ghalia
Dec 15, 2014
I'm creating new application: my ddl.sql is compiled well and I got my catalog.jar . Now I want to add a new stored procedure, so my procedure is:

import org.voltdb.SQLStmt;
import org.voltdb.VoltProcedure;
import org.voltdb.*;


public class SELECT2 extends VoltProcedure {

private final SQLStmt getUser = new SQLStmt("SELECT * FROM UC_USERS WHERE USER_NAME=? AND PASSWORD=?");

/**
* VoltDB procedures are subclass of {@link VoltProcedure} and run implicitly in transaction.
* @param username

* @param password

*/
public VoltTable[] run(String name, String password) throws VoltAbortException {

voltQueueSQL(getUser, name, password);

return voltExecuteSQL();
}
}



I create my procedure class and I add this line to my ddl.sql: "CREATE PROCEDURE FROM CLASS SELECT2 ;" When I copile my ddl I got an Error :


ERROR: [null]: Cannot load class for procedure: SELECT2
   caused by:
   java.lang.ClassNotFoundException: SELECT2
ERROR: [null]: VoltDB DDL Error: "Cannot load class for procedure: SELECT2
   caused by:
   java.lang.ClassNotFoundException: SELECT2" in statement starting on lineno: 63
------------------------------------------
Catalog compilation failed.
------------------------------------------

nshi
Dec 15, 2014
Hi Ghalia,

The compiler couldn't find the procedure class because it was not in the Java classpath. You need to compile the stored procedure into Java class file, then include the class file in the classpath when you compile the catalog. You can follow the steps in the documentation. http://docs.voltdb.com/UsingVoltDB/ChapAppBuild.php#BuildCompileCode
Ghalia
Dec 15, 2014
That's exactly what I have done
javac -cp "$CLASSPATH:/opt/voltdb-ent-4.9/voltdb/*:/opt/voltdb-ent-4.9/lib/*" SELECT2.java
nshi
Dec 15, 2014
You have to also include the directory that contains the class file in the classpath when you compile the catalog.

http://docs.voltdb.com/UsingVoltDB/BuildCompileCatalog.php
Ghalia
Dec 15, 2014
voltdb compile --classpath="/opt/voltdb-ent-4.9/voltdb/" -o flight.jar sample.sql

still the same error :(
Ghalia
Dec 15, 2014
it works well, thank you so much nshi :)
Lee
Jan 5, 2015
it works well, thank you so much nshi :)


Would you mind sharing what you did, please, to compile the procedure?
nshi
Jan 5, 2015
For example, to compile the catalog with the procedure SELECT2.java, you first have to compile the procedure source into Java class file,

javac -cp "$CLASSPATH:/opt/voltdb-ent-4.9/voltdb/*:/opt/voltdb-ent-4.9/lib/*" SELECT2.java


Assuming that the class file is in the current working directory, you then compile the catalog with the current working directory in the classpath,

voltdb compile --classpath="./" -o flight.jar sample.sql
Lee
Jan 5, 2015
Ok, thanks. I got the first part.

Question: in sample.sql ddl file, do you have reference to new procedure SELECT2.class?
nshi
Jan 5, 2015
Question: in sample.sql ddl file, do you have reference to new procedure SELECT2.class?


Yes, you do need to reference the procedure in the schema in order to compile it into the catalog. You can follow the syntax on the following page for referencing,

http://docs.voltdb.com/UsingVoltDB/BuildDeclareProcs.php
Lee
Jan 5, 2015
Got it!

Many thanks :)