hi,
I have written a java function as below. I am testing it using squirrel sql
client and embedded derby. The function is being invoked but
jdbc:default:connection returns null. I have tried both adding and removing the
Class.forName line with not much difference.
My errorlog file shows me a java.lang.NullPointerException and my execution log
has not gone beyond step 1 (that is it fails at getconnection). Can someone
pelase help.
Cheers
-Milind
package com.myorg.derbyfunctions;
import java.sql.*;
import java.util.*;
import java.io.*;
public class ActiveOrg
{
public static String GetActiveOrg (String status)
{
String org = "original";
try
{
BufferedWriter out2 = new BufferedWriter(new
FileWriter("C:\\ActiveOrgLog.txt"));
out2.write("1");
out2.flush();
//Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
Connection conn =
DriverManager.getConnection("jdbc:default:connection");
out2.write("2");
out2.flush();
String query = "INSERT into obj(TYPE) values('+status+')";
out2.write("3");
out2.flush();
System.out.println("Query"+query);
Statement stmnt = conn.createStatement();
stmnt.execute(query);
stmnt.close();
conn.close();
out2.close();
}
catch (Exception ex)
{
try
{
BufferedWriter out = new BufferedWriter(new
FileWriter("C:\\ActiveOrgError.txt"));
out.write(ex.toString());
out.close();
}
catch(Exception ex2)
{
ex2.printStackTrace();
}
}
return org;
}
}
/*
Declared as follows:
CREATE FUNCTION GetActiveOrg (status STRING)
RETURNS VARCHAR(255)
LANGUAGE JAVA
PARAMETER STYLE JAVA
READS SQL DATA
EXTERNAL NAME 'com.mymunshi.derbyfunctions.ActiveOrg.GetActiveOrg'
Invoked as follows
VALUES getactiveorg('Active')
*/