For administration needs, I need to create and replace stored procedures from Spring Repository. Has anyone already done this?
I tried to use following code(unfinished):
#Component
public class JdbcRepository {
#Autowired
private JdbcTemplate jdbc;
public void checkConn(){
jdbc.execute("create or replace package Z$CLIENT_INTERFACE_API as \n" +
" function CL_ORG_SEARCH_CREATE(p_request in clob) return clob;\n" +
"end Z$CLIENT_INTERFACE_API;\n" +
"/\n" +
"create or replace package body Z$CLIENT_INTERFACE_API as\n" +
" function CL_ORG_SEARCH_CREATE(p_request in clob) return clob\n" +
" is\n" +
" content_xml VARCHAR2(4000);\n" +
" p Dbms_Xmlparser.Parser;\n" +
" v_Doc Dbms_Xmldom.Domdocument;\n" +
" v_Root_Element Dbms_Xmldom.Domelement;\n" +
" v_Child_Nodes Dbms_Xmldom.Domnodelist;\n" +
" v_Child_Node Dbms_Xmldom.Domnode;\n" +
" v_Message_Id VARCHAR2(36);\n" +
" v_First_Char VARCHAR2(1);\n" +
" begin\n" +
" content_xml:= CAST(p_request as VARCHAR2);\n" +
" p := Dbms_Xmlparser.Newparser;\n" +
" dbms_xmlparser.setvalidationmode(p,False);\n" +
" dbms_xmlparser.parsebuffer(p,content_xml);\n" +
" v_Doc := dbms_xmlparser.getdocument(p);\n" +
" v_Root_Element := Dbms_Xmldom.getdocumentelement(v_Doc);\n" +
" return 'aaaaaaaaaaaaaaaaaaaaaaaaaa1';\n" +
" end;\n" +
"end Z$CLIENT_INTERFACE_API;\n" +
"/");
}
}
But whan I execute it, i take broken package in db. In same time, whan I run this from SQLDeveloper - all works perfect.
You are separating statements by both semicolon ; and slash /.
Try using only one of those, but not both. If that doesn't work either, try executing each statement separately with execute( )
This works perfect:
jdbc.execute("create or replace package Z$CLIENT_INTERFACE_API as \n" +
" function CL_ORG_SEARCH_CREATE(p_request in clob) return clob;\n" +
"end Z$CLIENT_INTERFACE_API;\n");
jdbc.execute("create or replace package body Z$CLIENT_INTERFACE_API as\n" +
" function CL_ORG_SEARCH_CREATE(p_request in clob) return clob\n" +
" is\n" +
" content_xml VARCHAR2(4000);\n" +
" p Dbms_Xmlparser.Parser;\n" +
" v_Doc Dbms_Xmldom.Domdocument;\n" +
" v_Root_Element Dbms_Xmldom.Domelement;\n" +
" v_Child_Nodes Dbms_Xmldom.Domnodelist;\n" +
" v_Child_Node Dbms_Xmldom.Domnode;\n" +
" v_Message_Id VARCHAR2(36);\n" +
" v_First_Char VARCHAR2(1);\n" +
" begin\n" +
" content_xml:= CAST(p_request as VARCHAR2);\n" +
" p := Dbms_Xmlparser.Newparser;\n" +
" dbms_xmlparser.setvalidationmode(p,False);\n" +
" dbms_xmlparser.parsebuffer(p,content_xml);\n" +
" v_Doc := dbms_xmlparser.getdocument(p);\n" +
" v_Root_Element := Dbms_Xmldom.getdocumentelement(v_Doc);\n" +
" return 'aaaaaaaaaaaaaaaaaaaaaaaaaa1';\n" +
" end;\n" +
"end Z$CLIENT_INTERFACE_API;");
Related
I'm building an Android app that contain SQLite DB and I was having a problem with translating SQLite saved data then I find a solution which is a method to get resource id of strings, and it worked just fine, the app was working fine then suddenly this error showed I don't know why, please help
The method, I used to get resource for string:
public static int getResId(String resName, Class<?> c) {
try {
Field idField = c.getDeclaredField(resName);
return idField.getInt(idField);
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
The code in the adapter
textViewname.setText(context.getString(R.string.product_Name)+" " + repo.getName());
textViewquantity.setText(context.getString(R.string.last_added_qty)+" " + repo.getQuantity() + " " + context.getResources().getString(mdatabase.getResId(repo.getItemsType(),R.string.class)));
textViewdate.setText(context.getString(R.string.entry_date)+" " + repo.getDate()+ " /"+context.getResources().getString(mdatabase.getResId(repo.getInOrOut(),R.string.class)));
textViewTotal.setText(context.getString(R.string.total_qty)+" " + repo.getTotal() + " " + context.getResources().getString(mdatabase.getResId(repo.getItemsType(),R.string.class)));
textviewlastUpdated.setText(context.getString(R.string.last_updated_date)+" " + repo.getUpdateDate() +" /"+context.getResources().getString(mdatabase.getResId(repo.getInOrOut(),R.string.class)));
textViewid.setText(context.getString(R.string.id)+" " + repo.getId());
textViewOutputqty.setText(context.getString(R.string.last_out_qty)+" " + repo.getOutputqty() + " " + context.getResources().getString(mdatabase.getResId(repo.getItemsType(),R.string.class)));
textViewpriceofsingleitem.setText(context.getString(R.string.retail_price)+" " + repo.getPrice() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewpriceofMultipleitem.setText(context.getString(R.string.wholesale_price)+" " + repo.getPriceofmultipleInput() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewProfitSIngle.setText(context.getString(R.string.retail_profit)+" " + repo.getProfitSingle() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewProfitMultiple.setText(context.getString(R.string.wholesale_profit)+" " + repo.getProfitMultiple() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewPurchasingPrice.setText(context.getString(R.string.purchasing_price)+" " + repo.getPurchasingPricePeranItem() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewTotalPurchasingPrice.setText(context.getString(R.string.total_purchase_price)+" " + repo.getTotalPurchasingPrice() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewTotalProfitSingle.setText(context.getString(R.string.total_retail_profit)+" " + repo.getTotalProfitperSingle() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewTotalProfitMultiple.setText(context.getString(R.string.total_wholesale_profit)+" "+ repo.getTotalProfitPerMultiple() + " " + context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewitemsIBox.setText(context.getString(R.string.num_unitsInBox)+" "+ repo.getItemsInBox());
textViewSinglePriceOfiteminBox.setText(context.getString(R.string.retail_price_perUnit)+ " " + repo.getSinglePriceofItemInBox()+" " +context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewMultipriceOfItemInBox.setText(context.getString(R.string.wholesale_price_perUnit)+" "+repo.getMultiplePriceofitemInBox()+" "+context.getResources().getString(mdatabase.getResId(repo.getCurrency(),R.string.class)));
textViewtotalItemsInBoexs.setText(context.getString(R.string.total_units)+" "+ repo.getTotalitemsInboxes() +" "+ context.getResources().getString(R.string.Pieces));
This error happens because you are trying to get resource that does not exist. It is because you store memory address which allocate to your string resource and possible it will change next time. I do not know what is your scenario but why you store it already in your strings it will never lost. I can help you to build another logic only when you tell what are you trying to achieve.
"UPDATE " + DatabaseFıelds.TABLE_NAME +
" SET " + DatabaseFıelds.SUBJECT_PROGRESS + " = " +
point + " WHERE " + DatabaseFıelds.SUBJECT_ID + " = " + id;
this query updates my value, but I want it to add to existing value. How can I fix this problem ?
I guess you want to add the value of point to the existing value of DatabaseFıelds.SUBJECT_PROGRESS, right? You can do it like this:
"UPDATE " + DatabaseFıelds.TABLE_NAME +
" SET " + DatabaseFıelds.SUBJECT_PROGRESS + " = " +
DatabaseFıelds.SUBJECT_PROGRESS + " + " + point +
" WHERE " + DatabaseFıelds.SUBJECT_ID + " = " + id;
it's works Thank you forpas"UPDATE " + DatabaseFıelds.TABLE_NAME +
" SET " + DatabaseFıelds.SUBJECT_PROGRESS + " = " +
DatabaseFıelds.SUBJECT_PROGRESS + " + " + point +
" WHERE " + DatabaseFıelds.SUBJECT_ID + " = " + id;
I am building a web portal through android and a query i am running through JDBC drivers is returning 0 where data should not be zero.
This is the query:
ResultSet set = statement.executeQuery("select it.itcod, it.itnam, it.packn, it.tradp, " +
"sum(nvl(itd.slbox,0) - nvl(itd.srbox,0) - nvl(itd.brbox,0) - nvl(itd.gsbox,0)) as sbox, " +
"sum(nvl(itd.slbbx,0) - nvl(itd.srbbx,0) - nvl(itd.brbbx,0) - nvl(itd.gsbbx,0)) as sbbx, " +
"SUM(NVL(itd.PRBOX,0) - NVL(itd.RPBOX,0) - NVL(itd.TRBOX,0)) as pbox, " +
"SUM(NVL(itd.PRBBX,0) - NVL(itd.RPBBX,0) - NVL(itd.TRBBX,0)) as pbbx " +
"from items it " +
"LEFT join item_daily itd " +
"on (it.cocod = itd.cocod " +
"and it.itcod = itd.itcod " +
"and ITD.ddate between " + fdate + " and " + tdate + ")" +
"WHERE IT.COCOD = " + COCOD +
"AND IT.DCODE = " + DCODE +
"AND NVL(IT.FREZE,'N')!='Y' " +
"group by it.cocod, it.itcod, it.itnam, it.packn, " +
" it.tradp, it.pkqty, it.dcode, it.freze, " +
" it.ishow, it.sltax, it.dcont, it.mcode, " +
" it.nwcod " +
"order by itnam ");
I have tried using resultsetmetadata but that does not work either.
you should be careful to this line
+ fdate + " and " + tdate
because you should use like this:
" .. to_date('"+fdate+"','***your_date_format') and to_date('"+fdate+"','***your_date_format')"
I am having a project based on JRuby on rails, now I am migrating this project to jruby-9.0.5.0 version.
In the code, ruby is called from Java file as shown below:
String source = new StringBuilder("require 'java'\n" +
"\n" +
"java_package 'jrubysource'\n" +
"class SystemFilePath\n" +
" attr_accessor :topDirCmd, :topDirNames\n" +
" java_signature 'SystemFilePath(String topDirCmd)'\n" +
" def initialize(topDirCmd)\n" +
" #topDirCmd = topDirCmd\n" +
" setTopDirectoryNames()\n" +
" end\n" +
"\n" +
" java_signature 'void setTopDirectoryNames()'\n" +
" def setTopDirectoryNames\n" +
" Open3.popen3(#topDirCmd) { |stdin, stdout, stderr, wait_thread|\n" +
" out = stdout.read\n" +
" err = stderr.read\n" +
" if err.size > 0 || out.size == 0\n" +
" #topDirNames = nil\n" +
" return\n" +
" end\n" +
" out = out.split(/\\n/).select{|a| a.match(/system_1/) && !a.match(/system_1\\/sim/)}.join(\"\\n\") + \"\\n\";\n" +
" topDirNames = out.split(/\\//).select{|a| a.match(/\\n$/) }.map(&:chomp)\n" +
" if topDirNames.size == 0 then\n" +
" #topDirNames = nil\n" +
" return\n" +
" end\n" +
" #topDirNames = topDirNames.sort.reverse\n" +
" }\n" +
" rescue Exception => e\n" +
" #topDirNames = nil\n" +
" end\n" +
"\n" +
"end\n" +
"").toString();
__ruby__.executeScript(source, "system_file_path.rb");
RubyClass metaclass = __ruby__.getClass("SystemFilePath");
metaclass.setRubyStaticAllocator(SystemFilePath.class);
if (metaclass == null) throw new NoClassDefFoundError("Could not load Ruby class: SystemFilePath");
__metaclass__ = metaclass;
}
public void setTopDirectoryNames() {
#SuppressWarnings("unused")
IRubyObject ruby_result = RuntimeHelpers.invoke(__ruby__.getCurrentContext(), this, "setTopDirectoryNames"); //Here i am calling ruby code from java file.
return;
}
Now, according to a JRuby API document "RuntimeHelpers" class is deprecated.
The document provides no alternative API. Please guide me towards an alternative as this is a blocker for me.
its an internal JRuby API ... you have a similar API available for every IRubyObject :
instead of
RuntimeHelpers.invoke(__ruby__.getCurrentContext(), this, "setTopDirectoryNames")
try :
this.callMethod(__ruby__.getCurrentContext(), "setTopDirectoryNames")
I am busy using a SQLite database with a java application and after updating the database successfully I get the following error
org.sqlite.jdbc4.JDBC4PreparedStatement#4e1c6f
Below is my update code
PreparedStatement update = con.prepareStatement("UPDATE highLeaker SET " + cyc + " = "
+ dataArray[3] + " , "
+ "gasSurveyOperator" + " = "
+ dataArray[1] + " , "
+ "gasSurveySerial" + " = "
+ dataArray[2] + " , "
+ "loss" + " = "
+ dataArray[4] + " , "
+ "comment" + " = "
+ dataArray[5] + " , "
+ "cycle" + " = '"
+ cycleT + "' , "
+ "date" + " = "
+ dataArray[6]
+ " WHERE leakerID = " + dataArray[0]+";");
System.out.println(update);
update.executeUpdate();
dataRow = CSVFile.readLine(); // Read next line of data.
You printed out the object. Also, I would highly recommend using place holders instead when executing SQL queries.