I am trying to call a java service from python. I am appending current timestamp to the file name to create a dynamic file name and passing it as a parameter in the java command. When I don't append the timestamp and pass the parameter as is, the code works but when I append the timestamp, I get Uncaught exception spotted in thread main: java.lang.AbstractMethodError error.
The code that doesn't works:
import subprocess
import time
Class DH:
#staticmethod
def restart_server(CLASSPATH, CLIENT_JVM_OPTIONS, SERVER_JVM_OPTIONS, SERVER_CONNECTION, DB_CONFIG, USER, SERVER_LOG, VERBOSE_OPTION):
subprocess.call("java -cp " + CLASSPATH + " " + CLIENT_JVM_OPTIONS + " -Djava.security.policy=..\\conf\\rmi.policy lib/main/Run -s " + SERVER_CONNECTION + " -user " + USER + " " + VERBOSE_OPTION + " shutdown SERVER")
timestr = time.strftime("%Y%m%d - %H%M%S")
log_file_name = "..\logs\DHLogFile" + timestr + ".log"
print(log_file_name)
subprocess.call("java -cp " + CLASSPATH + " " + SERVER_JVM_OPTIONS + " -Djava.security.policy=..\conf\\rmi.policy lib/main/Server -export " + SERVER_CONNECTION + " -db " + DB_CONFIG + " -log " + log_file_name + " -loglevel EFWIT " + VERBOSE_OPTION)
The code that works,
import subprocess
import time
Class DH:
#staticmethod
def restart_server(CLASSPATH, CLIENT_JVM_OPTIONS, SERVER_JVM_OPTIONS, SERVER_CONNECTION, DB_CONFIG, USER, SERVER_LOG, VERBOSE_OPTION):
subprocess.call("java -cp " + CLASSPATH + " " + CLIENT_JVM_OPTIONS + " -Djava.security.policy=..\\conf\\rmi.policy lib/main/Run -s " + SERVER_CONNECTION + " -user " + USER + " " + VERBOSE_OPTION + " shutdown SERVER")
log_file_name = "..\logs\DHLogFile.log"
subprocess.call("java -cp " + CLASSPATH + " " + SERVER_JVM_OPTIONS + " -Djava.security.policy=..\conf\\rmi.policy lib/main/Server -export " + SERVER_CONNECTION + " -db " + DB_CONFIG + " -log " + log_file_name + " -loglevel EFWIT " + VERBOSE_OPTION)
The full error is:
E 28/12/17-11:37:36.358 [-5] Uncaught exception spotted in thread main: java.lang.AbstractMethodError
E 28/12/17-11:37:36.358 [-5] java.lang.AbstractMethodError :
lib.main.a$a.a([Ljava/lang/String;I)I
java.lang.AbstractMethodError: lib.main.a$a.a([Ljava/lang/String;I)I
at lib.main.a.processArgs(SourceFile:646)
at lib.main.a.setupEnv(SourceFile:1078)
at lib.main.Server.main(SourceFile:157)
Could you please help me understand what is giving me AbstractMethodError Exception as I really want to have timestamp in the filename.
Related
I have the following data, which is a list of lists:
"segmentation": [[239.97,260.24,222.04,270.49,199.84,253.41,213.5,227.79,259.62,200.46,274.13,202.17,277.55,210.71,249.37,253.41,237.41,264.51,242.54,261.95,228.87,271.34]]
What I need to do is to parse the information to a JSON object without removing the second braces.
I tried it with Jackson, but this fails with any data types.
Do you have any idea how to handle this?
Parse to JsonNode will work. I think u try with invalid json. check:
String value = "{\n" +
" \"segmentation\": [\n" +
" [\n" +
" 239.97,\n" +
" 260.24,\n" +
" 222.04,\n" +
" 270.49,\n" +
" 199.84,\n" +
" 253.41,\n" +
" 213.5,\n" +
" 227.79,\n" +
" 259.62,\n" +
" 200.46,\n" +
" 274.13,\n" +
" 202.17,\n" +
" 277.55,\n" +
" 210.71,\n" +
" 249.37,\n" +
" 253.41,\n" +
" 237.41,\n" +
" 264.51,\n" +
" 242.54,\n" +
" 261.95,\n" +
" 228.87,\n" +
" 271.34\n" +
" ]\n" +
" ]\n" +
"}";
JsonNode jsonNode = new ObjectMapper().readTree(value);
I should starting a .jar several times like this
string JavaDir = #"C:\Program Files\Java\jdk1.8.0_161\bin\javaw.exe";
string MinecraftVersion = #"1.12.2";
string ForgeVersion = #"14.23.2.2611";
string Version = MinecraftVersion + #"-forge-" + ForgeVersion;
string ClientDir = #CurrentDirectory + #"\Client";
string Assets = ClientDir + #"\assets";
string Libraries = ClientDir + #"\libraries";
string Jar = ClientDir + #"\versions\" + MinecraftVersion + #"\" + MinecraftVersion + #".jar";
string Natives = ClientDir + #"\versions\" + MinecraftVersion + #"\" + MinecraftVersion + "-natives";
string Arguments = #"-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xmx1G -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:-UseAdaptiveSizePolicy -Xmn128M -Djava.library.path=""" + Natives + #""" -cp """ + Libraries + #"\net\minecraftforge\forge\" + MinecraftVersion + #"-" + ForgeVersion + #"\" + Version + #".jar"";""" + Libraries + #"\net\minecraft\launchwrapper\1.12\launchwrapper-1.12.jar"";""" + Libraries + #"\org\ow2\asm\asm-all\5.2\asm-all-5.2.jar"";""" + Libraries + #"\jline\jline\2.13\jline-2.13.jar"";""" + Libraries + #"\com\typesafe\akka\akka-actor_2.11\2.3.3\akka-actor_2.11-2.3.3.jar"";""" + Libraries + #"\com\typesafe\config\1.2.1\config-1.2.1.jar"";""" + Libraries + #"\org\scala-lang\scala-actors-migration_2.11\1.1.0\scala-actors-migration_2.11-1.1.0.jar"";""" + Libraries + #"\org\scala-lang\scala-compiler\2.11.1\scala-compiler-2.11.1.jar"";""" + Libraries + #"\org\scala-lang\plugins\scala-continuations-library_2.11\1.0.2\scala-continuations-library_2.11-1.0.2.jar"";""" + Libraries + #"\org\scala-lang\plugins\scala-continuations-plugin_2.11.1\1.0.2\scala-continuations-plugin_2.11.1-1.0.2.jar"";""" + Libraries + #"\org\scala-lang\scala-library\2.11.1\scala-library-2.11.1.jar"";""" + Libraries + #"\org\scala-lang\scala-parser-combinators_2.11\1.0.1\scala-parser-combinators_2.11-1.0.1.jar"";""" + Libraries + #"\org\scala-lang\scala-reflect\2.11.1\scala-reflect-2.11.1.jar"";""" + Libraries + #"\org\scala-lang\scala-swing_2.11\1.0.1\scala-swing_2.11-1.0.1.jar"";""" + Libraries + #"\org\scala-lang\scala-xml_2.11\1.0.2\scala-xml_2.11-1.0.2.jar"";""" + Libraries + #"\lzma\lzma\0.0.1\lzma-0.0.1.jar"";""" + Libraries + #"\net\sf\jopt-simple\jopt-simple\5.0.3\jopt-simple-5.0.3.jar"";""" + Libraries + #"\java3d\vecmath\1.5.2\vecmath-1.5.2.jar"";""" + Libraries + #"\net\sf\trove4j\trove4j\3.0.3\trove4j-3.0.3.jar"";""" + Libraries + #"\net\minecraftforge\MercuriusUpdater\1.12.2\MercuriusUpdater-1.12.2.jar"";""" + Libraries + #"\oshi-project\oshi-core\1.1\oshi-core-1.1.jar"";""" + Libraries + #"\net\java\dev\jna\jna\4.4.0\jna-4.4.0.jar"";""" + Libraries + #"\net\java\dev\jna\platform\3.4.0\platform-3.4.0.jar"";""" + Libraries + #"\com\ibm\icu\icu4j-core-mojang\51.2\icu4j-core-mojang-51.2.jar"";""" + Libraries + #"\net\sf\jopt-simple\jopt-simple\5.0.3\jopt-simple-5.0.3.jar"";""" + Libraries + #"\com\paulscode\codecjorbis\20101023\codecjorbis-20101023.jar"";""" + Libraries + #"\com\paulscode\codecwav\20101023\codecwav-20101023.jar"";""" + Libraries + #"\com\paulscode\libraryjavasound\20101123\libraryjavasound-20101123.jar"";""" + Libraries + #"\com\paulscode\librarylwjglopenal\20100824\librarylwjglopenal-20100824.jar"";""" + Libraries + #"\com\paulscode\soundsystem\20120107\soundsystem-20120107.jar"";""" + Libraries + #"\io\netty\netty-all\4.1.9.Final\netty-all-4.1.9.Final.jar"";""" + Libraries + #"\com\google\guava\guava\21.0\guava-21.0.jar"";""" + Libraries + #"\org\apache\commons\commons-lang3\3.5\commons-lang3-3.5.jar"";""" + Libraries + #"\commons-io\commons-io\2.5\commons-io-2.5.jar"";""" + Libraries + #"\commons-codec\commons-codec\1.10\commons-codec-1.10.jar"";""" + Libraries + #"\net\java\jinput\jinput\2.0.5\jinput-2.0.5.jar"";""" + Libraries + #"\net\java\jutils\jutils\1.0.0\jutils-1.0.0.jar"";""" + Libraries + #"\com\google\code\gson\gson\2.8.0\gson-2.8.0.jar"";""" + Libraries + #"\com\mojang\authlib\1.5.25\authlib-1.5.25.jar"";""" + Libraries + #"\com\mojang\realms\1.10.19\realms-1.10.19.jar"";""" + Libraries + #"\org\apache\commons\commons-compress\1.8.1\commons-compress-1.8.1.jar"";""" + Libraries + #"\org\apache\httpcomponents\httpclient\4.3.3\httpclient-4.3.3.jar"";""" + Libraries + #"\commons-logging\commons-logging\1.1.3\commons-logging-1.1.3.jar"";""" + Libraries + #"\org\apache\httpcomponents\httpcore\4.3.2\httpcore-4.3.2.jar"";""" + Libraries + #"\it\unimi\dsi\fastutil\7.1.0\fastutil-7.1.0.jar"";""" + Libraries + #"\org\apache\logging\log4j\log4j-api\2.8.1\log4j-api-2.8.1.jar"";""" + Libraries + #"\org\apache\logging\log4j\log4j-core\2.8.1\log4j-core-2.8.1.jar"";""" + Libraries + #"\org\lwjgl\lwjgl\lwjgl\2.9.4-nightly-20150209\lwjgl-2.9.4-nightly-20150209.jar"";""" + Libraries + #"\org\lwjgl\lwjgl\lwjgl_util\2.9.4-nightly-20150209\lwjgl_util-2.9.4-nightly-20150209.jar"";""" + Libraries + #"\com\mojang\text2speech\1.10.3\text2speech-1.10.3.jar"";""" + Jar + #" net.minecraft.launchwrapper.Launch --username " + Username + #" --version " + Version + #" --gameDir """ + ClientDir + #""" --assetsDir """ + Assets + #""" --assetIndex 1.12 --uuid " + UUID + #" --accessToken " + AccessToken + #" --userType legacy --tweakClass net.minecraftforge.fml.common.launcher.FMLTweaker --versionType Forge";
Client.StartInfo.FileName = #"""" + JavaDir + #"""";
Client.StartInfo.Arguments = Arguments;
Client.Start();
but the argument's limit is 8191 char and my argument is greater than the limit.
How I can run it?
EDIT: https://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html
You could make your program receive a file as an argument and read it.
The file would have one or more lines depending the number of arguments you'd like to pass to the program.
Your program would need to receive the file and parse it line by line.
when I execute the below native query :
String sql="merge into omfx.OM_PART_LOOKUP toLookup\r\n" +
" using omfx.OM_PART_LOOKUP fromLookup\r\n" +
" on(\r\n" +
" toLookup.PROJECT_ID= "+toProjectID+" and \r\n" +
" fromLookup.PROJECT_ID= "+fromProjectId +" and \r\n" +
" toLookup.scope =0 and \r\n" +
" UPPER(toLookup.PN) = UPPER(fromLookup.PN) and\r\n" +
" UPPER(toLookup.MAN) = UPPER(fromLookup.MAN)\r\n" +
" )\r\n" +
" when matched then update \r\n" +
" set \r\n" +
" \r\n" +
" toLookup.SEPN = fromLookup.SEPN ,\r\n" +
" toLookup.SE_MAN_ID = fromLookup.SE_MAN_ID ,\r\n" +
" toLookup.COM_ID = fromLookup.COM_ID ,\r\n" +
" toLookup.SE_MAN_NAME = fromLookup.SE_MAN_NAME ,\r\n" +
" toLookup.PART_CATEGORY = fromLookup.PART_CATEGORY \r\n" +
" \r\n" +
" \r\n" +
" when NOT matched then \r\n" +
" insert (PN,MAN,SEPN, SE_MAN_ID, COM_ID,SE_MAN_NAME ,PART_CATEGORY ,INSERT_DATE,PROJECT_ID)\r\n" +
" values (fromLookup.PN,fromLookup.MAN,fromLookup.SEPN, fromLookup.SE_MAN_ID, fromLookup.COM_ID , fromLookup.SE_MAN_NAME ,fromLookup.PART_CATEGORY , SYSDATE,"+toProjectID+") where\r\n" +
" fromLookup.PROJECT_ID = "+fromProjectId+" and fromLookup.scope = 0\r\n" +
" ";
System.out.println("projectOperationsBean.mergeManLookup()::sql=="+sql);
em.createNativeQuery(sql).getSingleResult();
I found the below error
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.4.2.v20130514-5956486): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-00900: invalid SQL statement
Error Code: 0
but when I execute this query in oracle ,It run good
does hibernate support to run MERGE statement or not?
thanks #Jorge Campos
MERGE is a DML statement so I must execute .executeUpdate() not .getSingleResult()
I am trying to print the plsql variable value (l_console_message) in Java. However, this approach doesn't seem to be working. I belive that something goes wrong at ResultSet bit. I am missing something here. Any idea, what goes wrong?
PreparedStatement statement = null;
try {
statement = connection.prepareStatement("\n" +
" declare " + "\n" +
" p_schema_name varchar2(400):= upper('" + schema + "'); " + "\n" +
" p_temp_table_name varchar2(400) := upper('temp_table_jobs_name'); " + "\n" +
" l_result varchar2(400); " + "\n" +
" l_owner varchar2(200); " + "\n" +
" l_job_name varchar2(200); " + "\n" +
" l_enabled varchar2(200); " + "\n" +
" l_console_message varchar2(4000); " + "\n" +
" cursor c1_temp_table_name is " + "\n" +
" select " + "\n" +
" table_name " + "\n" +
" from all_tables " + "\n" +
" where table_name = p_temp_table_name; " + "\n" +
" begin " + "\n" +
" open c1_temp_table_name; " + "\n" +
" fetch c1_temp_table_name into l_result; " + "\n" +
" if c1_temp_table_name %notfound then " + "\n" +
" execute immediate ' " + "\n" +
" create table '||p_schema_name||'.'||p_temp_table_name||' ( " + "\n" +
" schema_name varchar2 (1000), " + "\n" +
" job_name varchar2(1000), " + "\n" +
" status varchar2(100) " + "\n" +
" )'; " + "\n" +
" l_console_message := p_temp_table_name||' created.'; " + "\n" +
" dbms_output.put_line (l_console_message); " + "\n" +
" end if; " + "\n" +
" close c1_temp_table_name; " + "\n" +
" exception when others then " + "\n" +
" null; " + "\n" +
" end;");
ResultSet rs = statement.execute();
while (rs.next()){
System.out.println(rs.getString(l_console_message));
}
}
catch (SQLException e) {
System.out.println("ERROR: Unable to run SQL statements for schema " + schema + " in beforeMigrate: " + e.getMessage());
}
finally {
if (null != statement) {
try {
statement.close();
}
catch (SQLException se) {
System.out.println("ERROR: Unable to close statement in beforeMigrate: " + se.getMessage());
}
}
}
Thanks in advance :-)
The question linked to from a comment shows an example of what you need to do, but you seem to be struggling to translate that to your situation.
Your anonymous block doesn't (and can't) return a result set, so it shouldn't be executed as a query, and shouldn't be a prepared statement; you need to have a callable statement instead:
CallableStatement statement = null;
try {
statement = connection.prepareStatement("\n" +
...
Then you either need to assign the value of your PL/SQL variable to a bind variable placeholder:
...
" l_console_message := p_temp_table_name||' created.'; " + "\n" +
" ? := l_console_message; " + "\n" +
" end if; " + "\n" +
...
or don't have l_console_message at all (so it doesn't even need to be declared), just assign the string directly to a bind variable placeholder:
...
" ? := p_temp_table_name||' created.'; " + "\n" +
" end if; " + "\n" +
...
Either way the dbms_output call isn't useful here. (It is actually possibly you retrieve the dbms_output buffer from Java, but it's a lot more work).
Then you need to declare an OUT bind variable to receive the string, and call the statement with execute() rather than executeQuery():
statement.registerOutParameter(1, Types.VARCHAR);
statement.execute();
Then you can retrieve the string value that has been put in to the bind variable; e.g. to print it straight to console:
System.out.println(statement.getString(1));
The ResultSet, rs and loop have gone completely.
Your example has following issues:
Anonymous PL/SQL block can return nothing.
Variables declared in a PL/SQL block can't escape the scope. In your example l_console_message variable is visible only in the anonymous PL/SQL block, not in your Java code.
If you want to return a value (or a result set) from a PL/SQL code then you need a stand-alone or package subprogram. Or use the idea linked by #mario-tank where your host environment (your Java code) binds output variables.
Internet and StackOverflow have plenty of examples how to call PL/SQL code from Java.
I used mysqldump command to export/dump .sql file with rows like:
String cmd1 = mysqldump + " -h" + host + " -u" + username + " -p" + password + " " + "--compact --no-create-info " + "--where=ID=" + "'5b4ed36d-6152-4bfd-ad06-666f781e8bdc'" + " " + database + " " + "EMPLOYEE" + " " + "--result-file=" + "C:\\employee.sql";
This is the result of above command in a employee.sql file:
INSERT INTO `employee` VALUES ('Anette','Busch','2014-08-12','admin',' ','FALSE');
Now, I want to import the values from empolyee.sql file using command:
String cmd = mysql + " --user=" + username + " --password=" + password + " -e" + " source " + restoreFile;
The problem is I can't execute import command. I'm using the same import command for whole database, that works fine, but not in this case.
Thanks a lot for your guidance.