|
How to fetch data from multiple stored procedure
|
|
|
|
|
Make multiple calls to the database.
You can do it with one call but I am not a fan of that because it does not deal with error scenarios. So for example if the first call modifies the database but the second one doesn't the only way to handle that if the second call fails is to rollback the first. Even when it works getting the code correct is requires knowledge both initially and for maintenance programmers in the future.
But if you have a transactional work flow then you can create a single stored proc that represents that work flow and it can be responsible for calling other stored procs and also be responsible for correctly handling error conditions and determine how to report such errors.
Keep in mind as well that multiple result sets can be returned from a single proc (at least In at least a couple of dbs that I have worked with.) And that would need to be handled in the java db layer with either solution although it is much more obvious with the first solution that I suggested.
|
|
|
|
|
As mentioned, just call one right after the other or however you need to. Very easy.
|
|
|
|
|
Hi, I ask for help from anyone who can give it to me regarding a problem that I have not been able to solve for days.
I am creating a website with JSP + STRUTS1 technology that relies on a Tomcat 9.0.33 server and in the middle there is an Apache web server that acts as a proxy.
As a programming editor I use Eclipse. IT IS SPECIFIC THAT SO GIVING THAT THE ERROR I HAVE WHEN I START THE PROJECT WITHIN ECLIPSE IT DOES NOT MATTER THAT THERE IS APACHE IN THE MIDDLE BECAUSE ECLIPSE LAUNCHES ME LOCALHOST: 8080 / SITE NAME SO IT DOES NOT GO FROM APACHE UNTIL I TEST IN ECLIPSE
The problem is this:
I login from a home.jsp page through a form whose submit has been overwritten in jquery which makes an ajax call which calls a Login action of struts, in that action I put the user in session. At the end the call the ajax does window.location.replace (urlSite + "/"), that is relaunch the home of the site and I am still in home.jsp which however no longer shows the login form but a welcome note as it detects in session the user.
I state one thing to understand: a user can also be an admin and vice versa. In this site, if a user decides to become a recipe inserter, then a record is also inserted in the admin table with some user data and therefore we will have both a user and an admin connected to each other by a user_idUser field in the Admin table and admin_idAdmin in the table User. While browsing the site, if you enter some areas, the actions will remove the user in session to put his corresponding admin in session and when you exit these areas, the admin will remove himself from the session to put his corresponding user in session. These in-session objects are the UserBean classes (which contains an idAdmin property indicating its corresponding record in the Admin table) and AdminBean (which contains a UserBean object representing its corresponding user)
So far so good but the problem is a link always nalla home.jsp.
If I click on this link an action is called that removes the user from the session and puts me in session an admin corresponding to the user I have removed. The link is this:
<html: link action = "$ {urlBase} / Recipe? logoutUser = true" styleClass = "itemSubmenu"> <bean: message key = "organizeRecipe" /> </ html: link>
the logoutUser = true "attribute makes it clear to the Recipe action that it must remove the user from the session and put his admin in session.
Even so far so good because in the Recipe action in debug in Eclipse I see that it removes the userBean and inserts an adminBean.
Recipe action makes a forward on recipe.jsp and in this page I see that it detects in session an admin and not a user which is what I expect so ok.
Now the link is this
<html: link action = "$ {urlBase} / Recipe" styleClass = "itemSubmenu"> <bean: message key = "organizeRecipe" /> </ html: link>
which is right, only the logoutUser = true attribute is missing, because in the jsp there is a control that says that if there is a user in session then the link has the form with that attribute, while if in session there is an admin there is no attribute.
THE PROBLEM IS NOW: if I click on the link without attribute I expect that in the Recipe action now I see that the userBean in session is null and that there is instead an adminBean in session, INSTEAD THE CONTRARY DOES NOT HAPPEN, USER NOT NULL AND ADMIN NULL AS IF SOMETHING HAPPENED IN THE PASSAGE FROM RECIPE.JSP. I PROMISE THAT THE ID OF THE SESSION IS ALWAYS THE SAME FROM THE BEGINNING TO THE END BOTH IN THE JSP AND IN THE ACTIONS
I have no idea why I hope someone can help me thanks
|
|
|
|
|
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.demo.ds.api.user.repository.UserRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2021-03-23 21:40:25.384 ERROR 21956 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Field userRepository in com.example.demo.ds.api.SpringBootMultipleDatabaseApplication required a bean of type 'com.example.demo.ds.api.user.repository.UserRepository' that could not be found.
The injection point has the following annotations:
- <a href="https://www.codeproject.com/Members/org">@org</a>.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'com.example.demo.ds.api.user.repository.UserRepository' in your configuration.
|
|
|
|
|
<pre>Given an array A[] of size n. The task is to find the largest element in it.
Example 1:
Input:
n = 5
A[] = {1, 8, 7, 56, 90}
Output:
90
Explanation:
The largest element of given array is 90.</pre>
|
|
|
|
|
Set a variable to the first value.
Loop through the remainder one by one.
If the next value is larger than the saved one, replace the saved one with this value.
At the end of the loop the saved item will be the largest.
|
|
|
|
|
Query query = new Query();
query.addCriteria(Criteria.where("serviceCentreId").is(requestNumber)
.and("serviceSlots")
.elemMatch(Criteria.where("date").is(serviceRequestBean.getServiceSlot().get(0).getDate())
.and("slotBegin").is(serviceRequestBean.getServiceSlot().get(0).getSlotBegin())
.and("slotEnd").is(serviceRequestBean.getServiceSlot().get(0).getSlotEnd())
.and("slotBooked")
.elemMatch(Criteria.where("serviceRqId").is(serviceRequestBean.getServiceSlot().get(0).getSlotBooked().get(0).getServiceRqId())
)));
Update update = new Update();
update.set("serviceSlots.$[i].slotBooked.$[j].status", "Confirm")
how to write filterArray for this
|
|
|
|
|
Hi guys)
I'm just starting to learn Java and I want to become a Java developer. I don’t know what I should learn with Java to be able to get a job. Do you have any suggestions?
|
|
|
|
|
Start by learning the basics by reading books, doing tutorials, watching videos, etc. Then, I would suggest making some application. I learn best by doing so I'd make some sort of app.
|
|
|
|
|
|
Hello everyone
I'm trying to pass the matchday to the URL for the Http connection. I know I can't get a value from the EditText in the doInBackground method so I thought to get the value in the onPreExecute method. Of I then add the variable to the URL, the program doesn't recognise the String. I saw on StackOverflow you need to add the parameters in the execute method but I don't really have got that part of the explanation.
Does anyone have an idea how to add the matchday to the URL, entered in the EditText matchdayText?
Thanks in advance!
|
|
|
|
|
I have two different XML documents below and please note that they are having the same basic structure (schema).
Source XML
<root>
<name>String</name>
<description>String</description>
</root>
Test XML
<root>
<name>Test</name>
<description></description>
</root>
And I build this snippet function to compare those two XML documents.
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.Difference;
import org.custommonkey.xmlunit.IgnoreTextAndAttributeVal uesDifferenceListener;
import org.custommonkey.xmlunit.XMLUnit;
public static void main(String args[]) throws FileNotFoundException,
SAXException, IOException, ParserConfigurationException, XPathExpressionException {
String strSource = "<root><name>String</name><description>String</description></root>";
String strTest = "<root><name>Test</name><description></description></root>";
Document docSource = stringToXMLDocument(strSource);
Document docTest = stringToXMLDocument(strTest);
boolean result = isMatched(docSource, docTest);
if(result){
System.out.println("Matched!");
}else{
System.out.println("Un-matched!");
}
}
public static boolean isMatched(Document xmlSource, Document xmlCompareWith) {
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreAttributeOrder(true);
XMLUnit.setNormalizeWhitespace(true);
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
Diff myDiff = new Diff(xmlSource, xmlCompareWith);
myDiff.overrideDifferenceListener(new IgnoreTextAndAttributeValuesDifferenceListener());
return myDiff.similar();
}
public static Document stringToXMLDocument(String str) throws ParserConfigurationException, SAXException, IOException{
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setNamespaceAware(true);
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document document = docBuilder.parse(new InputSource(new StringReader(str)));
return document;
}
And here is the Maven dependency
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<version>1.6</version>
</dependency>
I am expecting those two XML documents are the same, but the function always returns false. Are there any ways that I can ignore the node text value when comparing two XML structures? As you can see, I already used IgnoreTextAndAttributeValuesDifferenceListener, but I still got the problem.
|
|
|
|
|
You are more likely to get help from the owners of the XMLUnit package.
|
|
|
|
|
How to generate and validate a software license key using java
|
|
|
|
|
import java.util.Scanner;
import java.io.*;
public class ReadFirstLine
{
public static void main(String[] args) throws IOException
{
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the name of a file: ");
String filename = keyboard.nextLine();
File file = new File(filename);
Scanner inputFile = new Scanner(file);
String line = inputFile.nextLine();
System.out.println("The first line in the file is:");
System.out.println(line);
inputFile.close();
}
}
Enter the name of a file: MyFriends.txt
Exception in thread "main" java.io.FileNotFoundException: MyFriends.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.jav a:138)
at java.util.Scanner.<init>(Scanner.java:611)
at ReadFirstLine.main(ReadFirstLine.java:21)
Java Result: 1
|
|
|
|
|
Enter the full path of the file, not just its name.
|
|
|
|
|
I am tryin to write the result of the pdf validation in to an excel but it is not working can anyon help below is the code i wrote
<pre>public static void PDF_File_Validation(String object, String data) throws IOException{
try{
Log.info("PDF Documents has been Verified");
List<String> outputs = new ArrayList<String>();
System.setProperty("webdriver.chrome.driver", Constants.Path_driver);
WebDriver driver = new ChromeDriver();
File[] files = new File(object).listFiles(File::isFile);
for (File file: files) {
String fileExtension = file.getName().split("\\.")[file.getName().split("\\.").length - 1];
if (fileExtension.toLowerCase().equals("pdf")) {
String fileUrl = "file:///" + file.getAbsolutePath();
driver.get(fileUrl);
URL url = new URL(driver.getCurrentUrl());
InputStream is = url.openStream();
BufferedInputStream fileToParse = new BufferedInputStream(is);
PDDocument document = null;
String output;
try {
document = PDDocument.load(fileToParse);
output = new PDFTextStripper().getText(document);
} finally {
if (document != null) {
document.close();
}
fileToParse.close();
is.close();
}
outputs.add(output);
Thread.sleep(2500);
boolean test = output.contains(data);
String test1=Boolean.toString(test);
FileInputStream file1 = new FileInputStream(Constants.Path_Result+DriverScript.s+"\\PDFResults.xlsx");
@SuppressWarnings("resource")
XSSFWorkbook workbook = new XSSFWorkbook(file1);
XSSFSheet sheet = workbook.getSheetAt(0);
Row row1 = sheet.createRow( 0 );
if (test1.contains("false")){
Log.info("The "+file.getName()+" File does not Contain "+ data+"="+"Failed");
}else{
Log.info("The "+file.getName()+" File Containes "+ data+"="+"Passed");
}
for ( int cellIndex = 0; cellIndex < output.length(); cellIndex++ ) {
Cell cell = row1.createCell( cellIndex );
if (test1.contains("false")){
cell.setCellValue("The "+file.getName()+" File does not Contain "+ data+"="+"Failed");
}else{
cell.setCellValue("The "+file.getName()+" File Containes "+ data+"="+"Passed");
}
}
file1.close();
FileOutputStream outFile =new FileOutputStream(Constants.Path_Result+DriverScript.s+"\\PDFResults.xlsx");
workbook.write(outFile);
outFile.close();
}}
driver.quit();
return;
}catch(Exception e){
Log.error("PDF Documents was not Verified --- " + e.getMessage());
DriverScript.bResult = false;
}
}
|
|
|
|
|
Member 13938502 wrote: but it is not working Please exlain what that means.
|
|
|
|
|
I am tryin to write the result of the pdf validation in to an excel but it is not working can anyon help below is the code i wrote
<pre>public static void PDF_File_Validation(String object, String data) throws IOException{
try{
Log.info("PDF Documents has been Verified");
List<String> outputs = new ArrayList<String>();
System.setProperty("webdriver.chrome.driver", Constants.Path_driver);
WebDriver driver = new ChromeDriver();
File[] files = new File(object).listFiles(File::isFile);
for (File file: files) {
String fileExtension = file.getName().split("\\.")[file.getName().split("\\.").length - 1];
if (fileExtension.toLowerCase().equals("pdf")) {
String fileUrl = "file:///" + file.getAbsolutePath();
driver.get(fileUrl);
URL url = new URL(driver.getCurrentUrl());
InputStream is = url.openStream();
BufferedInputStream fileToParse = new BufferedInputStream(is);
PDDocument document = null;
String output;
try {
document = PDDocument.load(fileToParse);
output = new PDFTextStripper().getText(document);
} finally {
if (document != null) {
document.close();
}
fileToParse.close();
is.close();
}
outputs.add(output);
Thread.sleep(2500);
boolean test = output.contains(data);
String test1=Boolean.toString(test);
FileInputStream file1 = new FileInputStream(Constants.Path_Result+DriverScript.s+"\\PDFResults.xlsx");
@SuppressWarnings("resource")
XSSFWorkbook workbook = new XSSFWorkbook(file1);
XSSFSheet sheet = workbook.getSheetAt(0);
Row row1 = sheet.createRow( 0 );
if (test1.contains("false")){
Log.info("The "+file.getName()+" File does not Contain "+ data+"="+"Failed");
}else{
Log.info("The "+file.getName()+" File Containes "+ data+"="+"Passed");
}
for ( int cellIndex = 0; cellIndex < output.length(); cellIndex++ ) {
Cell cell = row1.createCell( cellIndex );
if (test1.contains("false")){
cell.setCellValue("The "+file.getName()+" File does not Contain "+ data+"="+"Failed");
}else{
cell.setCellValue("The "+file.getName()+" File Containes "+ data+"="+"Passed");
}
}
file1.close();
FileOutputStream outFile =new FileOutputStream(Constants.Path_Result+DriverScript.s+"\\PDFResults.xlsx");
workbook.write(outFile);
outFile.close();
}}
driver.quit();
return;
}catch(Exception e){
Log.error("PDF Documents was not Verified --- " + e.getMessage());
DriverScript.bResult = false;
}
}
modified 11-Feb-21 11:41am.
|
|
|
|
|
Start by reading what it says at the top of the page: this is not the place for programming enquiries.
Try here: Ask a Question[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
This is not the place to ask your question. See above:
Quote: Got a programming question?
Get me coffee and no one gets hurt!
|
|
|
|
|
this is not the place to ask programming questions. see above comments telling you to see above.
basically just walk around all day and look above you.
good luck in the QA forum(s).
|
|
|
|
|
Slacker007 wrote: walk around all day and look above you. that's a sure fire way to fall in a hole.
|
|
|
|
|
I keep reading this as "How to write excellent insults with JavaScript."
I bet people would answer that programming question in the lounge!
|
|
|
|