Recently I discovered power of Java, I'm coming from Perl, Python world so I'm at very beginning. I have firm understanding of OOP and I'm ready for new challenges. I have question regarding writing to database performance and theory.
Basically as my personal project I'm trying to write some small program or addon which will enable me to write concurrently to database. Let's say that I have some software and that has FIFO output to database in single stream, but since the output interface is not fast enough congestion can occur if the input to the system is high.
I would like to extend that software with addon which will take that one output stream and create 2,3,4 concurrent input streams towards database. API from that software is provided so I can redirect output to third-party extensions and apps.
I need to print contents of database to excel file.Apache POI is the solution but I am not finding a way to print the DB column names/headers into the excel.
E.g.:
incase csv we have opencsv CSVWriter writer = new CSVWriter(new FileWriter(fileName)); System.out.println("writer"); writer.writeAll(rs, true);
will print the db contents with the column headers dynamically whatever the query may be.
Any solution where we can print data and column names without know the query previously as we are getting query at the run time and each time the query is different.
I'm trying to understand the concurrent model of each EJB session bean types.
The singleton is well documented and seems clear to me... Only one instance and many threads using it but each method by default is synchronized because @Lock is defaulted to WRITE. We can let multiple threads use on method with @Lock(READ).
The stateless beans are in a pool I think I read somewhere that the container will ensure only one thread is using one instance at a time but this instances are recycled/reused so many threads can use the same instance but one at a time.
Is this correct ? or is it possible that multi-threading occur in one instance of SLSB ?If in the client I obtain a single reference of a SLSB and share this "instance reference" in multiple threads is it true that all the threads could use different instances on the server side ?
The stateful instance I obtain in the client is linked to one server instance and any method call will target the same instace. If many threads are using the same reference, all method calls will be synchronized and waiting for a certain amount of time that can be defined in @AccessTimeout and if the timeout is reach will end with a ConcurrentAccessException.
Can we use @Lock(READ) and let many thread use the same method like in a singleton ?
I put the code on pastebin.com because it is relatively long. How to improve this code that does not occur starvation and was ucziwy terms of writers and readers.
I was wondering if you use an IDE when writing programs?Can you use J frame when using command line or is it just used with an IDE and do you go into framing in the book?I have taken programming classes and I am still stuck.
I have copied a wav file as explained in [URL] ..... When trying to play my new file, it runs but no sound is hear. My reading and writing class is as explained in another post in the site:
This is the function that reads the file:
// read a wav file into this class public boolean read(DataInputStream inFile) { myData = null; byte[] tmpInt = new byte[4]; byte[] tmpShort = new byte[2];
[Code] ....
I can't hear the copied wav file, but still the wav file is correctly copied...
I am writing a program in Java where a user adds 1 stamp on a letter for every five sheets of paper in it (or fraction thereof)For example, I if I have 11 sheets of paper, I add 3 stamps. If the total number of stamps is more than 3, they don't send it.
I need to ask the user how many sheets of paper they have, and then calculate the appropriate number of stamps based on the formula above. I just don't know how to write the math formula to calculate this, i'm stuck. So far I have:
package test; import java.util.Scanner; public class LetterMailing { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); int numSheets;
I've looked at multiple sources and everyone is saying different stuff. Which one should I be using? FileWriter/FileReader, other people was saying PrintWriter, and one even said : "Formatter" which is the one I'm doubting mostly. My purposes for writing files is for like saving maps, saving high scores, etc.
I'm working on assignment for a class where I'm creating a home utility auditor. Basically the user has to pick from a list of appliances and then input various fields to calculate a total cost. When the user chooses "washer" from the list of appliances, they must enter in values for 2 separate fields, and will then click calculate to get total cost. I've been trying to implement this through an if, else statement, but it's not wanting to calculate a total cost and I'm running into errors. I've put the code below.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { // The calculate button will multiply the 3 fields that the user inputs: //cost*Kw used*hours used=total cost of operation float num1,num2, num3, result; //now, parse the text to a type float num1= Float.parseFloat (costField.getText ());
I have accountsData.txt file in my default package, this is the file it should be writing to and reading from.
There is an ATM class, which has the main in it. From here the program is supposed to work like an atm, you type in your account number and can withdraw or deposit. It is supposed to then write the changes to the file.
//Read from a file. public void loadAccounts(String inputFileName) throws IOException { Scanner fin = new Scanner(new File(inputFileName)); // Variables to store the values.[/color] int account = 0; double balance = 0.0;
Okay so I have to write a method to compute the following series: m(i)= 1/3 + 2/5 +....+ (i / 2i+1) and write a test program that displays a table " i = m(i)" 1=0.3333 2=0.7333....all the way down to 20 which is 9.2480. I have written something and cannot seem to get the sum of the fractions to display .
public class ExtraCredit1 { public static void main(String[] args) { double num; double sum = 1;
public class Tester { public static void main(String[] args) { Product p1 = new Product(); p1.loadFromFile("Monitor.pr"); System.out.println("Actual: " + p1.toString()); System.out.println("Expected: Product [id=12345, name=Monitor, description=A freakin great monitor!]");
p1.setId(11111); p1.setName("another product"); p1.setDescription("Description of another product!");
[code]....
The expected output is what my program should be doing and the actual output is what it's doing instead. As you can see, my code works for the middle test. But I cannot understand why it won't load the first fileFor the second half, the id and the quantity are separated by a comma... I'm not really sure how to deal with that. As you can see, I tried using a delimiter, but it doesn't seem to be doing any good.
I realized I wasn't capitalizing certain things, and when I did it i was able to run the compiler. is there a utility or tool that auto formats the capitalization and such? I read kathy mentioning about eclipse I installed I don't know where that feature is.
I need to write a program that, when a button is pressed, will add the user input to a table AND write it to a sequential data file. I have everything done accept for how to write the data sequentially(all input data on the same line in the file). The following is part of the code:
private void submitButtonActionPerformed(java.awt.event.ActionEvent evt) { DefaultTableModel dtm = (DefaultTableModel)jTable1.getModel(); dtm.addRow(new Object[]{donorName.getText(),charityName.getText(),donationAmmount.getText()}); //Adds user input to the table try { FileWriter writer = new FileWriter("FundraisingInformation.txt",true);//Creates file or adds to it BufferedWriter bw = new BufferedWriter(writer);
[code].....
I would need the file output to be in the following format:
donorName charityName donationAmmount
As I said, using the .write(bw) i know how to make it look like:
I have a java code that should sort an array of names based on the last name. e.g jane a, jane b, jane z, jane d should be jane a, jane b, jane d, jane z. I have the following code but for some reasons, the s1 in the comparator method is always null.
public class ShuffleName { public static void sortNames(String[] names){ Arrays.sort( names, new Comparator<String>() { public int compare( String s1, String s2 ) { String s1last = s1.split("s+")[1]; String s2last = s2.split("s+")[1]; return s1last.compareTo(s2last);
What I'm tasked to do, is to make a simple Java class that forms a "V" based on whatever height the user would desire, made out of stars "*", and spaces " ".
For example, if a user desires a "V" with a height of 3, it would look print out something like;
* * * * *
Where a "V" with a height of 5 would look something like:
* * * * * * * * *
(That one didn't look too good, but you get the point, it's suppose to be 5 "high" and shaped like a "V"). The problem I have, is that I don't see what loops within loops within loops I would need to build something like this.
All the easy stuff like asking the user what height they want and such, I can handle, but I don't see how this thing is suppose to be coded, to print out a decent-looking and right-sized "V" in the console.
public static void main(String[] args) { int height = 3; for (int i = 0; i < height; i++) { for (int j = 0; j < 2/(height+1)+1; j++) { if(j == i) {
[Code] ....
Looked like something of a good start, and it drew me half (!) of the "V" in the size I wanted. Am I on to it here, or am I on the moon in terms of progress? I need the entire "V", not just a nice "".
I am trying to write to an http server, but nothing happens. I can read from the file, I just cannot write to it and no errors are thrown. I do not know how to proceed.
Specifically, I have a text file on my server, and I can read from it (the text file already has content), but I cannot write to it. And, no exceptions are thrown.
url = new URL("http://kajl-ig.com/txt.txt"); urlConn = url.openConnection(); urlConn.setDoInput(true); urlConn.setDoOutput(true); urlConn.setUseCaches(false); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(urlConn.getOutputStream())); String s = "TEST Successfull!";
[code].....
The second code, I got from some random website, and I was desperate so I tried it. I am not sure what the
urlConn.setRequestProperty (String, String);
method does, so I removed it and it reads fine it just cannot write.
I want to write Metadata to a JPEg image using the Exif 'XPComment' field.
Because the standart Java libraries does not support writing metadata I tried using the JAI (Java Advanced Imaging) and Sanselan (Commons Sanselan - Commons ) but I was not able to find an example or something else which create a working code.
I am trying to write a Float Array to a file but it is only writing the last line of the array to a file. I have also attached the entire assignment as a zip file with all required files. Here is the part of the code I am having issues with: