|
karengsh wrote: I find generic List is rather hard to use in java cos of the compiler can't recognize the type etc...from what I have read. I have no idea where you read that, but it was certainly not in the Java documentation: List (Java Platform SE 7 )[^].
|
|
|
|
|
Hello Richard,
I read it in stackoverflow. Unfortunately, I did not have the link now.
It says something erasure ....
Anyway, I have reworked my code as follows but I do not know why my insert for this arrayList is still not working
SubjectDAOImpl :
public class subjectDAOImpl implements subjectDAO {
private final String INSERT_QRY1 = "INSERT INTO project.subject subject VALUES (?)";
<pre>public void insertSubject(subject s) throws MyDataException {
try {
s = new subject();
ArrayList<String>subj;
openConnection();
String qry = INSERT_QRY1;
ps = connection.prepareStatement(qry);
int i =0;
subj = new ArrayList<String>();
while(i< subj.size()){
ps.setString(1,subj.get(i));
ps.addBatch();
i++;
ps.executeBatch();
if (ps !=null )
closeConnection();
}
}
catch (SQLException e) {
e.printStackTrace();
Controller :
<pre>
try{
subject m = new subject();
ArrayList<String>subj = new ArrayList<String>();
String[] sub = request.getParameterValues("subject");
for (String s : sub)
subj.add(s);
m.setSubj(subj);
mgr.insertSubject(m);
I used Eclipse to debug, the controller part seems correct. Unfortunately, I do not why Eclipse is not debugging on my sujectDAOImpl...Have been trying for hours....
There were alot of strange errors like :
RequestFacade.getParameterValue Source not found
WebappClassLoader(WebappClassLoaderBase).loadClass(String)
NonRegisteringDriver.class
but I am not able to get the debugger to debug on the serveral breakpoints I placed on the DAOImpl class.
Hope you can tell me what's wrong with my code.
Tks.
|
|
|
|
|
Your insertSubject method makes no sense. You are passed a subject reference which you immediately overwrite with a newly created object, which will be empty. You also create a new array (subj = new ArrayList<String>(); ) and then try to iterate its contents. As to the other errors, you will need to look at the code where they occur.
|
|
|
|
|
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
Scanner keyb = new Scanner(System.in);
System.out.println("Input:");
String in = keyb.nextLine();
System.out.println("Output:");
String out = keyb.nextLine();
int sum = 0;
long product = 1;
double count = 0;
ArrayList<Integer> med = new ArrayList<Integer>();
File file = new File(in);
Scanner f = new Scanner(file);
while ( f.hasNextInt() ) {
int num = f.nextInt();
sum += num;
product *= num;
med.add(num);
++count;
}
PrintWriter pw = new PrintWriter(out);
pw.println("Sum: " + sum);
pw.println("Product: " + product);
pw.println("Average: " + (sum/count));
Collections.sort(med);
int middle = med.length /2;
if (med.length % 2 == 1) {
pw.println("Median: " + med.get(middle));
} else {
pw.println("Median: " + (med.get(middle) + med.get(middle-1)) / 2);
}
}
}
modified 2-Jun-17 19:36pm.
|
|
|
|
|
Member 12877930 wrote: med.length
l think you are trying to get the size of the ArrayList, you can use
med.size which will give you the size of the list.
However, remember that Collection is an interface, thus not supposed to be instantiated. So you can use any of the implementation classes to sort.
|
|
|
|
|
|
There are key differences between an ArrayList and an Array. You are trying to find the length of an ArrayList, not an array. You are looking for med.size() not med.length
|
|
|
|
|
1) im trying this in jsp (working)-
${examques[0].question}
${examques[1].question}
2) i want like this-
int i=0;int j=2
${examques[i].question}
${examques[j].question}
IT IS NOT WORKING.......
3) Same method i want to apply in javascript with these variable ...
please help.......
|
|
|
|
|
|
I am asked to copy an array and return a deep copy of the idx index, this is what i did but told i am still not copying the array. I have no idea what to do.
public static int[][] getOrder(int idx) {
int[][] product = null;
int noOrders;
if (idx >= 0 && idx < ORDERS.length) {
for (noOrders = 0; noOrders < ORDERS.length; noOrders++) {
if (noOrders == idx) {
product = ORDERS[noOrders].clone();
}
}
} else {
System.err.println("idx: " + idx + " is not valid!");
return null;
}
return product;
}
}
|
|
|
|
|
Am new in Java and l have an issue which l urgently need a help. But let me explain in detail so that my question could be understood.
First of all, there is a domain and there is also a PC with windows server 2012 which have an Active directory. And through this Active Directory, all other PCs in the domain can be seen.
Now, l was given a project which l need to develop a programme that have to access files and folders in each PC seen in the Active Directory.
How can l achieve that? Which lib or API do l use. l need any idea to achieve that.
l have used the DirContext in JNDI API, still l don't get.
l need help in that. Thanks
|
|
|
|
|
|
Hello;
I'm beginner in java ; I want to implement the ACO algorithme for solving a problem of shortest path (minimize the time of target) in java and I don't know where I should start.
Please I need a help if you have.
thanks;
|
|
|
|
|
Start with something simpler. You say you are a beginner, so what have you actually learned up to now? Have you worked through all the tutorials at The Java™ Tutorials[^]?
|
|
|
|
|
Thank you for your answer;
yes,I read a lot of toturials for java and I win to implement an interface for writing the informations of my subject(departure and arrival hours of vehicle and their price ; target time...) in a file .txt
and reading them .
now I need to know how can adapt the ant colony system for this problem? what is the steps?
thank you in advance.
|
|
|
|
|
Member 13220854 wrote: what is the steps? 1. Research the subject.
2. Create a design for your program (GUI or Text based)
3. Code and Test.
|
|
|
|
|
I'm in last step"code and test" and I have a problem in this step exactly.
I implement the graph (nodes "cities"; arcs"line of the mode of transport" and the modes of transport )
now I search to know how can implement the algorithm of ant colony system for calculate the minimum times for a travel from a node source to a node destiation ?
Thank you for your help.
|
|
|
|
|
Implementing an algorithm is merely writing the code to do the calculations. I do not know this algorithm so cannot offer any suggestions.
|
|
|
|
|
so thanks a lot for your help ;
|
|
|
|
|
Hi all,
I am trying to execute javascript in a PDF that will allow the form to be submitted via email with a subject line that will pull a value from a field in the form. I am able to get the email portion to work, but I have not been able to customize the subject line to pull from the field. Below is the base script I am using to send the email without the customized subject line:
this.submitForm({
cURL: "mailto:aamos@lrrc.com?subject=TSC Form&body=",
cSubmitAs: "PDF"
});
The field I am wanting to pull from is labeled "Name". Below was one of my attempts, all of which have not worked.
Failed Script:
this.submitForm({
var Name = this.getField("Name").value;
cURL: "mailto:aamos@lrrc.com?subject=TSC Form (Name)&body= ) ",
cSubmitAs: "PDF"
});
Can some one point me in the right direction or help me with where I went wrong in the script? I am new to this, and glad I was able to execute the first script successfully but I feel I am in over my head with the customization.
Thanks in advance your your assistance.
AA
|
|
|
|
|
Member 13220732 wrote: javascript
javascript != java. You might have better luck asking in the appropriate forum.
Speed of sound - 1100 ft/sec
Speed of light - 186,000 mi/sec
Speed of stupid - instantaneous.
|
|
|
|
|
Thank you! As you can tell, I am a rookie. Googling only gets you so far. I have reposted, thank you!
|
|
|
|
|
UPDATE data SET
full_name = "SARA",
reg_num = "dawdawdaw",
note = "note",
price = 15,
date = 2017-05-17,
totalPay = 16,
expiration_date = 2017-06-16,
WHERE id = 1;
if I run this SQL statement it throws the following syntax error:
WHERE[*] id = 1 "; expected "identifier"; SQL statement:
What did I do wrong?
modified 15-May-17 4:09am.
|
|
|
|
|
Is this Java code? If so, then some of your variables look to be in the wrong format. Strings need to be bounded with double quotes. Not sure about those data values.
|
|
|
|
|
Thanks for your reply I edited the values of the String type with the double quotes
|
|
|
|