Error on Oracle : ORA-29541 - java

I'm trying to call a bash script within a oracle database through a java script. To test it I just tried a basic script :
#!/bin/bash
echo "It works !"
And the java script that I use is :
import java.lang.*;
import java.io.*;
public class UAM_TOOLS{
public static String Toto () throws IOException {
String[] unixCommand = {"/home/oz380/toto.sh"};
String pwd;
Process p = Runtime.getRuntime().exec(unixCommand);
BufferedReader input =
new BufferedReader
(new InputStreamReader(p.getInputStream()));
pwd = input.readLine();
input.close();
return pwd;
}
};
I granted all the permissions that had to be granted and I created the function in my database :
SQL> CREATE OR REPLACE FUNCTION TOPI RETURN VARCHAR2
2 as language java
3 name 'UAM_TOOLS.Toto() return java.lang.String';
4 /
But then when I call the function :
select TOPI from dual;
or :
SQL> set serveroutput on;
SQL> DECLARE
2 G VARCHAR2(50);
3 BEGIN
4 G := UAM.TOPI;
5 DBMS_OUTPUT.PUT_LINE(G);
6 END;
7 /
It doesn't work and prints the error :
ORA-29541: class UAM.UAM_TOOLS could not be resolved
I don't really understand what the problem can be. If anyone does I would be really thankful.

Before the
CREATE FUNCTION
step you need to compile your class at command line
$>javac UAM_TOOLS.java
or using an IDE sth like Eclipse
that will generate compiled class with .class extension. For your case it will be UAM_TOOLS.class
And you still need to upload it to database on command line where the host which db runs on it
$>loadjava -user yourUserName/youPass#Yourdb UAM_TOOLS.class
after that 2 step you can resume with create function step.

Related

Java commons cli parser not recognizing command line arguments

This should be very simple but I am not sure why its not working. I am trying pass arguments with a name (So I can pass arguments in any order) using the apache commons CLI library but It seems to be not working. I want to pass the arguments from eclipse IDE. I know this part is not the problem because I am able to print the arguments with args[0] kind.
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
public class MainClass {
public static void main(String[] args) throws ParseException {
System.out.println(args[0]);
Options options = new Options();
options.addOption("d", false, "add two numbers");
CommandLineParser parser = new DefaultParser();
CommandLine cmd = parser.parse( options, args);
if(cmd.hasOption("d")) {
System.out.println("found d");
} else {
System.out.println("Not found");
}
}
The above lines are exactly like the examples given online but i dont know why its not working. I am struggling this from a day now. Please help where I am going wrong.
According to the examples name of the parameter should be present in command line
Property without value
Usage: ls [OPTION]... [FILE]...
-a, --all do not hide entries starting with .
And the respective code is:
// create the command line parser
CommandLineParser parser = new DefaultParser();
// create the Options
Options options = new Options();
options.addOption( "a", "all", false, "do not hide entries starting with ." );
In this scenario correct call is:
ls -a or ls --all
With value separated by space
-logfile <file> use given file for log
Respective code is:
Option logfile = OptionBuilder.withArgName( "file" )
.hasArg()
.withDescription( "use given file for log" )
.create( "logfile" );
And call would be:
app -logfile name.of.file.txt
With value separated by equals
-D<property>=<value> use value for given property
The code is:
Option property = OptionBuilder.withArgName( "property=value" )
.hasArgs(2)
.withValueSeparator()
.withDescription( "use value for given property" )
.create( "D" );
And call would be:
app -Dmyprop=myvalue

how to pass an empty String from perl Script to java file as a command line argument

I have a Script order.pl it has 3 variables
$dbcount=$ARGV[0];
if($dbcount == ""){$dbcount = 196001;}
$Num_Batches =$ARGV[1];
if($Num_Batches == ""){$Num_Batches=1;}
print "batches:$Num_Batches\t";
$TimeStamp = $ARGV[2];
if($TimeStamp == ""){$TimeStamp = "";}
$DBFetch = 'java GetWOConfHold_Auto '. $dbcount." ".$TimeStamp ;
print "DBFetch:$DBFetch\n";
print "timestamp :$TimeStamp";
system($DBFetch);
Here the java file is GetWOConfHold_Auto.java and i want to sent both dbcount and empty String to the GetWoConfHol_Auto java file as a command line arguments but
while running it is showing
perl order.pl 196000 1
batches:1 timestamp: dbcount:196000 DBFetch:java GetWOConfHold_Auto 196000
timestamp :args[0] 19600
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at GetWOConfHold_Auto.main(GetWOConfHold_Auto.java:18)
no of picking updates data : 0
No data.exiting
I tried to print the timestamp but it is showing
timestamp :args[0] 19600 not the empty String
and in java it is stopping at the main method signature
I want to sent the empty String to java file as a command line argument. and i check if timestamp is null just go and pick the value from the properties file
In the string variant of system, you need to quote the empty string.
Have you tried the list version of system?
my $DBFetch = system 'java', 'GetWOConfHold_Auto' ,$dbcount, $TimeStamp;

How to solve lua errors: "attempt to index ? (a nil value)" [duplicate]

This question already has an answer here:
Attempt to index local 'v' (a nil value)
(1 answer)
Closed 5 years ago.
There has been a lot of post about this kind of error and most people say it is related to table and array indexing problems. But I am not using tables at all, I am just trying to call a library function I made and I get this error. Here is the lua script called from java:
String script = new String (
"function event_touch ( )"
+ " pb.open_form ('view_monster');"
+ " print ('I ran the lua script');"
+ "end");
PBLUAengine.run_script(script, "event_touch");
This gives me the following error when trapping the exception:
"function event_touch ( ) pb.open_form ('view_monster'); print ('I ran the lua script');end:1 attempt to index ? (a nil value)"
The run_script() function calls the script like this( I am using luaj):
public static LuaValue run_script ( String script )
{
try
{
LuaValue chunk = s_globals.load( script );
return chunk.call();
}
catch ( Exception e)
{
Gdx.app.error ("PBLUAengine.run_script()", e.getMessage() );
}
return null;
}
The library method goes like this and the same piece of code works when called from java:
static class open_form extends OneArgFunction
{
public LuaValue call (LuaValue formname)
{
String tmpstr = (String ) CoerceLuaToJava.coerce(formname, java.lang.String.class );
try
{
PBscreen_game.hide_subscreen(PBscreen_game.MENU_SUBS);
PBscreen_game.show_subscreen ( PBscreen_game.FORM_SUBS);
PBsubscreen_form.open_form ( new PBform_regular ( tmpstr ) );
}
catch (Exception e)
{
Gdx.app.error("PBLUAlibrary.open_form", e.getMessage());
}
return valueOf ( 0 );
}
}
It basically convert the lua parameter to string, create a new from and pass in parameter the string.
The declaration of the library functions goes like this:
public LuaValue call( LuaValue modname, LuaValue env )
{
LuaValue library = tableOf();
library.set( "open_form", new open_form() );
library.set( "open_system_form", new open_system_form() );
env.set( "pb", library );
return library;
}
Which could be the only "table" I can see in the whole system. This is generally used link the right class with the right function name.
Anybody have an idea?
most people say it is related to table and array indexing problems
It's related to table and array indexing. If you try to index an object and that object is nil, you'll get that error:
I am not using tables at all [..] Here is the lua script:
pb.open_form
pb is being indexed. It's probably nil.
I seems that I solved the problem by adding a require line to include the library. So the new script is:
String script = new String (
"require 'com.lariennalibrary.pixelboard.library.PBLUAlibrary'"
+ "function event_touch ( )"
+ " pb.open_form ('view_monster');"
+ " print ('I ran the next button lua script');"
+ "end");
It ask to include my library class which will add all the "pb.*" functions. I probably deleted the line by error, or managed to make it work somehow without it. Since this library will be required by all script, I might append it by default before each script I try to run.
Thanks Again

How to get an App category from play store by its package name in Android?

I want to fetch the app category from play store through its unique identifier i.e. package name, I am using the following code but does not return any data. I also tried to use this AppsRequest.newBuilder().setAppId(query) still no help.
Thanks.
String AndroidId = "dead000beef";
MarketSession session = new MarketSession();
session.login("email", "passwd");
session.getContext().setAndroidId(AndroidId);
String query = "package:com.king.candycrushsaga";
AppsRequest appsRequest = AppsRequest.newBuilder().setQuery(query).setStartIndex(0)
.setEntriesCount(10).setWithExtendedInfo(true).build();
session.append(appsRequest, new Callback<AppsResponse>() {
#Override
public void onResult(ResponseContext context, AppsResponse response) {
String response1 = response.toString();
Log.e("reponse", response1);
}
});
session.flush();
Use this script:
######## Fetch App names and genre of apps from playstore url, using pakage names #############
"""
Reuirements for running this script:
1. requests library
Note: Run this command to avoid insecureplatform warning pip install --upgrade ndg-httpsclient
2. bs4
pip install requests
pip install bs4
"""
import requests
import csv
from bs4 import BeautifulSoup
# url to be used for package
APP_LINK = "https://play.google.com/store/apps/details?id="
output_list = []; input_list = []
# get input file path
print "Need input CSV file (absolute) path \nEnsure csv is of format: <package_name>, <id>\n\nEnter Path:"
input_file_path = str(raw_input())
# store package names and ids in list of tuples
with open(input_file_path, 'rb') as csvfile:
for line in csvfile.readlines():
(p, i) = line.strip().split(',')
input_list.append((p, i))
print "\n\nSit back and relax, this might take a while!\n\n"
for package in input_list:
# generate url, get html
url = APP_LINK + package[0]
r = requests.get(url)
if not (r.status_code==404):
data = r.text
soup = BeautifulSoup(data, 'html.parser')
# parse result
x = ""; y = "";
try:
x = soup.find('div', {'class': 'id-app-title'})
x = x.text
except:
print "Package name not found for: %s" %package[0]
try:
y = soup.find('span', {'itemprop': 'genre'})
y = y.text
except:
print "ID not found for: %s" %package[0]
output_list.append([x,y])
else:
print "App not found: %s" %package[0]
# write to csv file
with open('results.csv', 'w') as fp:
a = csv.writer(fp, delimiter=",")
a.writerows(output_list)
This is what i did, best and easy solution
https://androidquery.appspot.com/api/market?app=your.unique.package.name
Or otherwise you can get source html and get the string out of it ...
https://play.google.com/store/apps/details?id=your.unique.package.name
Get this string out of it - use split or substring methods
<span itemprop="genre">Sports</span>
In this case sports is your category
use android-market-api it will gives all information of application

How to export data from Cassandra to CSV file using Java

I tried to use the DataStax Java Driver, but then i found out it does not support the COPY command, does anyone know other methods of exporting data using Java? Thanks.
For example i have created event table:
cqlsh:kunderatest> describe TABLE event ;
CREATE TABLE event (
id text,
log text,
timstamp bigint,
PRIMARY KEY (id)
)
and inserted three record
cqlsh:kunderatest> INSERT INTO event (id, log , timstamp ) VALUES ( '1', 'my first log' , 12345678);
cqlsh:kunderatest> INSERT INTO event (id, log , timstamp ) VALUES ( '2', 'my second log' , 12345679);
cqlsh:kunderatest> INSERT INTO event (id, log , timstamp ) VALUES ( '3', 'my third log' , 12345680);
1) First you can do it by using CQLSH client. Now you can export the data of event table into any file (in this case it is log.txt) by executing following command.
cqlsh:kunderatest> COPY kunderatest.sample (id, name, age, address) TO './log.txt' WITH DELIMITER = '|' AND QUOTE = '''' AND ESCAPE = '''' AND NULL = '<null>';
3 rows exported in 0.042 seconds.
You can validate the command output by verify log.txt file. Hope it will help you.
2) Second you can also use Runtime utility of Java to execute the export command in order to achieve the goal.
create a file (let say command.txt) and paste the following export command into that file.
COPY kunderatest.sample (id, name, age, address) TO './log.txt' WITH DELIMITER = '|' AND QUOTE = '''' AND ESCAPE = '''' AND NULL = '<null>'
after creating the file and adding the above command into that file do the following it will export the data into file which is given in export command.
String exportCommand = cassandraHome + "bin/cqlsh " + hostname + " " + rpcPort + " -f command.txt"; // file which holds export command
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(exoprtCommand);
// for keep tracking the log, you can do following.
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null)
{
}
Note: cassandrahome is path of cassandra package directory. in my case it is /usr/local/apache-cassandra-2.0.6

Categories

Resources