|
Having used JNI multiple times before I would note that I would never use it again.
If the JNI code crashes then it takes the VM down. And there is little or nothing you can do to stop that.
For convenience I am going to refer to the needed non-java code as C/C++ below but it applies to any language that can be used to create an exe.
And there is a very viable option
1. Create a C/C++ wrapper which allows the target code to be run as and exe.
2. The exe has a control API. There are three ways to control it: Stdio, files or TCP/IP. Or perhaps pipes.
3. Use Java process API to run and manage the exe. That allows one to start, stop and kill it.
4. The Java code uses the control API to control it. This can include everything: configuration, passing binary data, statistics, health checks even a request for the exe to exit.
Advantages over JNI
1. It cannot crash the VM
2. The external code runs in its own process space.
3. The C/C++ code can be unit tested independently from Java code.
4. The C/C++ code is its own deliverable. Move the exe into the Java deployment space. It can even be packaged into a jar (any file can be) but of course it would need to be extracted into the file system.
5. The java code can be tested independently from the java code if the control interface is built carefully.
|
|
|
|
|
When you are running in Java:
ResultSet rs = stmt.executeQuery("SELECT Column FROM Table WHERE Condition");
Does the database create in memory a list with all the rows/values that have the given condition, and it is keeping that list until the rs is close? Or it will only keep the first value, and move to the next value when rs.next() is called?
I'm asking this because you can give it the command to FETCH NEXT X ROWS ONLY , and in case you have a database with millions of entries, that would save time and resources when you only want X rows, and not all of them that match the given condition.
Or the FETCH is only a hard limit to know when to stop with sending the rows/values one by one?
|
|
|
|
|
Valentinor wrote: SELECT Column FROM Table WHERE Condition
First keep in mind that is SQL. It is sent as is to the database.
Valentinor wrote: Does the database create in memory a list with all the rows/values that have the given condition
That is not how the jdbc is defined to work. But a bad driver could definitely do that. There is (or was) a jdbc/odbc 'text' driver and presumably it could have loaded everything into memory. But that was basically a toy anyways.
The next() technically loads it. But drivers I have actually looked at usually use some sort of batch request that might load 10, 100, etc, and then wait for the next to pull from the local set. I think I even recall somewhere that can be adjusted. The initial set as somewhat low value.
Valentinor wrote: FETCH NEXT X ROWS ONLY
How you do that depends on the database (see above). But every query you write should always be constrained (the where clause) and most should have a limit on the number of rows. The result should be paged.
Only time that would not be true when you know for a fact that the target table has an extraordinarily low growth factor. Only ones I know for sure like that are application enumeration tables.
Table examples where you should ALWAYS include the paging mechanism are things like customers, users, orders, events, etc.
Valentinor wrote: database with millions of entries, that would save time and resources when you only want X rows,
That is a complex statement and there is no simple answer.
You should NEVER, for example, allow for a design where a UI could expect a user to view 'millions' of rows. As a developer if you see a requirement like that you should insist that the requirements be changed to include reasonable constraint restrictions. Some examples
1. Require a date range, account number, customer store, etc.
2. Do a count(*) with the constraints in place and throw an error if the result is larger than X (say 10,000) which would then require the user (in the UI) to add more constraints to narrow the result.
And such queries should ALWAYS require a page and row size. So for example 'page 5', 'size 20'. The backend then restricts (hard code) the max size to something like 1000.
Additionally the users (whoever they are) might claim that they 'need' all of those rows. A person can never process millions of rows so such a claim for a user is ridiculous. The user in such a case always knows that they are looking for something very specific like a email, customer name, account number, etc.
However the other possible need is some automated process is going to consume that result. And in that case you should design a batching system that can dump large files wo some location (FTP server) to be processed by that external service. There are a vast number of problems that should be addressed in such a request, of which just one, is that you do not want to be dumping the entire contents of that table every day or every hour. Not to mention that there might even be some consideration about who actually owns that data and who pays for the processing to deliver it.
|
|
|
|
|
jschell wrote: That is not how the jdbc is defined to work.
OK, good. I'm the only developer for now, so I'm working on everything, and DB/SQL isn't something I'm good at, but I don't want to make a bad DB when it comes to performance.
jschell wrote: But a bad driver could definitely do that.
I'm using Oracle JDBC driver 11, so I would say that is out of the question.
jschell wrote: The result should be paged.
Is this a good example of paging?[^] Unfortunately, that isn't something I know of.
jschell wrote: You should NEVER, for example, allow for a design where a UI could expect a user to view 'millions' of rows.
Oh, no way that. By that I meant something else, but you answered it here:
jschell wrote: That is not how the jdbc is defined to work. But a bad driver could definitely do that.
Thank you for all the info!
|
|
|
|
|
Valentinor wrote: Is this a good example of paging?[^]
Using the following in google to look for examples.
PLSQL paging query
|
|
|
|
|
There's a phrase in TSQL parlance:
"Row by Agonizing Row"
(In order to give proper credit to the conspiracy that does the stabbing here I'd have to misquote someone so I'll just type in stuff which an eleventh grade high school teacher could type if she were quoting herself).
Look up INDEX and think "I'll use INDEX, in 'automatic assign of an index' and just DROP the original index and reassign it after I do all the tabulation"
|
|
|
|
|
I'm trying to find a file based on the starting eight digits extracted from an excel sheet for every iteration. I am receiving the error notice "Local variable CaseID declared in an enclosing scope must be final or effectively final" so i am using the code below and still appears to be fresh, so I don't know how to correct this, Even after it happen to be a straightforward repair.
package Chrome;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class ValidateInput {
public static void main(String[] args) throws Throwable {
File src = new File("C:\\Users\\Z246379\\Documents\\TestDataFolder\\ValidateInput.xlsx");
FileInputStream fis = new FileInputStream(src);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet Sheet1 = wb.getSheetAt(0);
int i1 = 2;
String data0 = Sheet1.getRow(2).getCell(0).getStringCellValue();
String data01 = Sheet1.getRow(2).getCell(1).getStringCellValue();
String caseID = Sheet1.getRow(i1).getCell(2).getStringCellValue();
String Desc = Sheet1.getRow(2).getCell(3).getStringCellValue();
String ICF = Sheet1.getRow(1).getCell(4).getStringCellValue();
String CRPT = Sheet1.getRow(1).getCell(5).getStringCellValue();
System.out.println("Called openBrowser");
String exePath = System.getProperty("user.dir")+"\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", exePath);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("start-maximized");
options.addArguments("--no-sandbox");
options.addArguments("--disable-extensions-except");
options.addArguments("disable-extensions");
WebDriver driver = new ChromeDriver(options);
driver.get("https://client.abc.com");
driver.findElement(By.xpath("//input[@id='userid']")).sendKeys(data0);
driver.findElement(By.xpath("//body[@class='no-nav']/div[@id='wrapper']/header[@class='header']/div[@class='container']/div[@class='menu']/div[@class='drop']/div[@class='login-form']/form[@method='POST']/div[2]/input[1]")).sendKeys(data01);
driver.findElement(By.xpath("//input[@value='Sign In']")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//span[@class='wpsNavLevel2'][contains(text(),'EZ-Test')]")).click();
Thread.sleep(3000);
driver.get("https://ezt.abc.com/Test/inputFiles/selectValidateInput/selectValidateInput.xhtml");
while (caseID != null)
{
caseID = Sheet1.getRow(i1).getCell(2).getStringCellValue();
driver.findElement(By.xpath("//input[@id='mainForm:caseId']")).sendKeys(caseID);
driver.findElement(By.xpath("//input[@id='mainForm:testBedDesc']")).sendKeys(Desc);
driver.findElement(By.xpath("//select[@id='mainForm:customRptOptions']")).sendKeys(ICF);
driver.findElement(By.xpath("//span[@id='mainForm:customReportLabel']")).click();
File dir = new File("C:\\Users\\Z333379\\Documents\\Test beds");
FilenameFilter filter = new FilenameFilter() {
public boolean accept (File dir, String name) {
return name.startsWith(caseID);
}
};
String[] children = dir.list(filter);
if (children == null) {
System.out.println("Either dir does not exist or is not a directory");
} else {
for (int i=0; i< children.length; i++) {
String filename = children[i];
System.out.println(filename);
driver.findElement(By.xpath("//input[@id='mainForm:comprehensive']")).sendKeys("C:\\Users\\Z246379\\Documents\\Test beds\\" + filename);
}
}
driver.findElement(By.xpath("//button[@id='mainForm:reset']")).click();
i1=i1+1;
}
}
}
This is from the source I read, I don't know how to define an inner local class with a mutable variable. Is that correct? This problem appears to be at the bottom of the code, at the caseID variable.
modified 3-Jan-23 7:15am.
|
|
|
|
|
Try this:
final String caseId1 = caseID;
FilenameFilter filter = new FilenameFilter() {
public boolean accept (File dir, String name) {
return name.startsWith(caseId1);
}
};
|
|
|
|
|
i want to locate a file based on the first eight digits extracted from an excel sheet for every iteration. I am receiving the error notice "Local variable CaseID declared in an enclosing scope must be final or effectively final" so i am using a code below and it still showing it as fresh, and i dont know how to correct it, even after it appears to be a straightforward repair.
|
|
|
|
|
Without seeing your actual code it is difficult to make any useful suggestions. Please edit your question and show the relevant code and explain where the error occurs.
|
|
|
|
|
|
Hello everyone, I have a list of Objects, whose attributes include a BLOB object, taken from a database, how can I display the image in JSP?
This is the servlet code with which I take objects from the DB
<pre lang="Java">
while(rs.next()) {
Rapportino rapp = new Rapportino();
String nome_operaio = rs.getString("nome_operaio");
String cognome_operaio = rs.getString("cognome_operaio");
String ruolo_operaio = rs.getString("ruolo_operaio");
Date data = rs.getDate("data");
String luogo = rs.getString("luogo");
Blob foto = rs.getBlob("file");
rapp.setNome_operaio(nome_operaio);
rapp.setCognome_operaio(cognome_operaio);
rapp.setRuolo_operaio(ruolo_operaio);
rapp.setData(data);
rapp.setLuogo(luogo);
rapp.setFoto(foto);
rapportini.add(rapp);
}
request.setAttribute("rapportini", rapportini);
request.getRequestDispatcher("rapportino.jsp").forward(request,response);
And this is the jsp, for now I have not implemented the code for the BLOB
<pre lang="HTML"><pre>
<% List<Rapportino> rapportini = (List<Rapportino>)request.getAttribute("rapportini");%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Rapportini</title>
</head>
<body>
<h1>Rapportino:</h1>
<table>
<c:forEach items="${rapportini}" var="rapp">
<tr>
<td><c:out value="${rapp}" /></td>
</tr>
</c:forEach>
</table>
<a href="homepage_admin.jsp">Torna alla home</a>
</body>
</html>
|
|
|
|
|
Above is too confusing.
Your goal is to display an image (not a blob) which comes from a database
1. Read the blob into a memory representation
2. Figure out how to display an image, ANY image. Perhaps hard code one for testing
3. Figure out how to convert data from 1 to what you need for step 2.
Step 1 and Step 2 are INDEPENDENT. Do one then the other. Do not try to do both at the same time.
|
|
|
|
|
|
There is no 'best', there are just choices. So start by looking at the features available in any of the languages that you are familiar with. If you are not familiar with any languages then you need to think about some study materials.
|
|
|
|
|
Looking at his profile and message history, he's a spammer trying to push his food delivery app.
Spammer (nithin sethu)[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks. And I have a feeling I flagged him already the other day. 
|
|
|
|
|
Which part?
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
1) Un negocio de perfumería efectúa descuentos en sus ventas según el importe de éstas, con la siguiente escala:
- Si el importe es menor a $100 corresponde un descuento del 5%
- Si el importe es de entre $100 (inclusive) y hasta $500 (inclusive) corresponde un
descuento del 10%
- Si el importe es mayor a $500 corresponde un descuento del 15%
El dueño le solicitó a Ud., futuro programador, un programa donde se deba ingresar el importe original a pagar por el cliente y que luego se calcule e informe por pantalla el precio final con el descuento que corresponda ya aplicado.
2) Hacer un programa para ingresar por teclado la nota obtenida por un alumno en una determinada materia y luego emitir el cartel aclaratorio que corresponda, de acuerdo a las siguientes condiciones:
- “Sobresaliente”, si la nota fue 10.
- “Distinguido”, si la nota fue 9 ó 8.
- “Bueno”, si la nota fue 7 ó 6.
- “Aprobado”, si la nota fue 5 ó 4.
- “Insuficiente”, si la nota fue 3, 2 ó 1.
- “Ausente”, si la nota fue 0.
7) Hacer un programa para ingresar por teclado las cuatro notas de los exámenes parciales obtenidas por un alumno en una determinada materia y luego emitir el cartel aclaratorio que corresponda, de acuerdo a las siguientes condiciones:
- “Promociona”, si obtuvo en los cuatro exámenes nota 7 o más.
- “Rinde examen final”, si obtuvo nota 4 o más en por lo menos tres exámenes.
- “Recupera Parciales”, si obtuvo nota 4 o más en por lo menos uno de los exámenes.
- “Recursa la materia”, si no aprobó ningún examen parcial.
modified 3-Dec-22 19:11pm.
|
|
|
|
|
We won't do your home work for you, but you could at least write it in English.
|
|
|
|
|
I have this problem where I solved it when my array is not empty.
My issue is whem the array is empty. I tried to put an condition but it's useless.
I got this error "[ERROR] CycleSwapTest.testCycleSwapEmptyCaseShift:44 � ArrayIndexOutOfBounds Index 0 o..."
Proceed to CycleSwap class and implement its static methods:
void cycleSwap(int[] array)
Shifts all the elements in the given array to the right by 1 position.
In this case, the last array element becomes first.
For example, 1 3 2 7 4 becomes 4 1 3 2 7.
void cycleSwap(int[] array, int shift)
Shift all the elements in the given array to the right in the cycle manner by shift positions.
Shift value is guaranteed to be non-negative and not bigger than the array length.
For example, 1 3 2 7 4 with a shift of 3 becomes 2 7 4 1 3.
For a greater challenge, try not using loops in your code (not mandatory).
Note that input array may be empty.
Examples
Code Sample:
int[] array = new int[]{ 1, 3, 2, 7, 4 };
CycleSwap.cycleSwap(array);
System.out.println(Arrays.toString(array));
Output:
[4, 1, 3, 2, 7]
Code Sample:
int[] array = new int[]{ 1, 3, 2, 7, 4 };
CycleSwap.cycleSwap(array, 2);
System.out.println(Arrays.toString(array));
Output:
[7, 4, 1, 3, 2]
Code Sample:
int[] array = new int[]{ 1, 3, 2, 7, 4 };
CycleSwap.cycleSwap(array, 5);
System.out.println(Arrays.toString(array));
Output:
[1, 3, 2, 7, 4]
My code is:
<pre>class CycleSwap {
static void cycleSwap(int[] array) {
int shift = 1;
reverse(array, 0, array.length - 1);
reverse(array, shift, array.length - 1);
}
static void cycleSwap(int[] array, int shift) {
reverse(array, 0, array.length - 1);
reverse(array, 0, shift - 1);
reverse(array, shift, array.length - 1);
}
private static void reverse(int[] nums, int i, int j) {
while (i < j) {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
i++;
j--;
}
}
public static void main(String[] args) {
{
int[] array = new int[]{1, 3, 2, 7, 4};
CycleSwap.cycleSwap(array,2);
System.out.println(Arrays.toString(array));
}
{
int[] array = new int[]{};
CycleSwap.cycleSwap(array);
System.out.println(Arrays.toString(array));
}
{
int[] array = new int[]{};
CycleSwap.cycleSwap(array, 3);
System.out.println(Arrays.toString(array));
}
}
}
Output:
[7, 4, 1, 3, 2]
[]
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at com.epam.rd.autotasks.CycleSwap.reverse(CycleSwap.java:22)
at com.epam.rd.autotasks.CycleSwap.cycleSwap(CycleSwap.java:16)
at com.epam.rd.autotasks.CycleSwap.main(CycleSwap.java:43)
Do you know what is the problem?
|
|
|
|
|
Why are you trying to access elements of an empty array? But either way you can use the length property of the array to test whether it is empty or not.
|
|
|
|
|
"
Why are you trying to access elements of an empty array? "
Because is in the statement description. I have some failed tests and I thought maybe because of that.
Note that input array may be empty.
I tried like this, but still it's not working.
<pre>class CycleSwap {
static void cycleSwap(int[] array) {
int shift = 1;
reverse(array, 0, array.length - 1);
reverse(array, shift, array.length - 1);
}
static void cycleSwap(int[] array, int shift) {
reverse(array, 0, array.length - 1);
reverse(array, 0, shift - 1);
reverse(array, shift, array.length - 1);
}
private static void reverse(int[] nums, int i, int j) {
while (i < j) {
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
i++;
j--;
}
}
public static void main(String[] args) {
{
int[] array = new int[]{};
if (array.length == 0) {
System.out.println(0);
} else {
CycleSwap.cycleSwap(array, 2);
System.out.println(Arrays.toString(array));
}
}
}
}
I get this result:
[ERROR] CycleSwapTest.testCycleSwapEmptyCaseShift:44 � ArrayIndexOutOfBounds Index 0 o...
How can I fix that?
|
|
|
|
|
Probably because your test for zero length is in the wrong place. You need to test it at the beginning of each of the methods cycleSwap and reverse , since those are the places where the error can occur.
|
|
|
|
|
Yeah! You're right! I don't know why I didn't think about that!
|
|
|
|
|