Use the code tags without the ' in the tag:
//code
Don't put the ' in the above tags
Use the code tags without the ' in the tag:
//code
Don't put the ' in the above tags
File file=new File(rout);
FileWriter text=new FileWriter(file,[B]true[/B]);
BufferedWriter out=new BufferedWriter(text);
out.newLine();
out.write("a String");
I have something that will make it write in continuation. Give me sometime to find it, because I have something else important to do now.
Have you declared a package? Try running a simpler "Hello World" program, because the error you are getting doesn't have to do with the sql part. Are you getting the error when you compile or when you run?
There is a suggestion:
File file=new File(rout);
FileWriter text=new FileWriter(file);
BufferedWriter out=new BufferedWriter(text);
out.newLine();
out.write("a String");
Don't wait too much, you will be disappointed. Meaning that you should post the compile errors you get for each class and then we will try to help you. Because you are not using code tags and it is hard to read your code
The break; takes you out of the switch{}.
Even if it did take you out of the method, which it doesn't, the method is declared int:
public static int getValue(char c) {}
The above method has ONE char argument,
and it must return an int value.
If you you don't want it to return anything it should be void: public static void getValue(char c) {}
or else you will need somewhere in your method, probably at the end, a return statement which will return the int that you want to return
There is a better way to socialize:
3 words for you
World Of Warcraft:icon_smile:
I don't know if there are better ways to do it but here is my suggestion. When the user logs in take the username and when the user goes to another page, send the username with the other data as hidden:
<input type="hidden" value="<%= username%>" name="username">
When you get to the other page take the username and check if it is null or not.
If someone who hasn't logged in tries to view a page, the username will be null and you will redirect him to the login page.
Moreover when a user wants to log out you can set the username to be null and send it with the request to whatever page you want to send it.
When you login using userId and password, take from the db the name and pass it to the next page
You don't need to know by heart the exact definition of OOP in order to be able to write code. Just know how to use objects correctly.
What have you written so far, what is your problem and how good are you concerning HTML, jsp pages and DB queries
if (str1==str2) returns false correctly because they are two different objects.
if ( str1.equals(str2) ) will return true, because it compares their values.
Have you added the changes to your code? If you have what errors do you get know and what is your problem? Perhaps you should post you newly updated code and tell us in what you are having difficulties
I would suggest first to get the int value of the method and then check it if it is -1:
int i = name.indexOf(",");
if (i!=-1)
FirstName = name.substring(0,i);
You could use:
DecimalFormta
or try Math.round after you have multiplied the result with 100..00 and then divide t=with the same number depending on the precision you want:
double result = 0.0999999999;
double d = result *1000;
d = Math.round(d);
d = d/1000;
To start with the class's constructor is wrong declared:
Right way:
class SomeClass {
public SomeClass() {
}
}
Wrong way:
class SomeClass {
public [B]void [/B] SomeClass() {
}
}
The getters return null because the values first,lastName are null. If you see the constructor they never get values.
The constructor:
public Name( String name)
{
name = FirstName + LastName;
}
is wrong. The argument's value must be inserted somwhere:
public Name( String n)
{
name = n;
}
The first constructor and the while are also wrong.
What you have inside the while is wrong because you are changing the value of name. You don't want that, that's the value that you are checking and have at the for loop. If you change that, the for-loop is going to get messed up.
Read the String API and you will find 2 or 3 useful methods to use without using for or while loops.
The class is called GUIEx and you have a method called LabelFrame() in which you call super().
Meaning that super(), should called only inside the constructor and LabelFrame is not a constructor since the class's name is GUIEx
I would suggest copying the query in an sql editor and try to run it by replacing only the '?' with values.
You can use whatever you want but they are different.
String s="";
You create a new String with the value to be an empty String: "". Meaning that s exists and you can use it:
you can call s.toString().If you print this: System.out.println(">"+s+"<"); it will print: ><
s.length will return 0
BUT
String s=null;
You don't create an object, s does not exist, and you cannot call any methods.
If you try to call any of the previous methods:
s.toString(), s.length, or any other method you will get a NullPointerException at runtime.
Plus:
String s=null;
(s==null): returns true
( s.equals("") ): will not execute, will throw an Exception
String s="";
(s==null): returns false;
( s.equals("") ): will execute and return true
Actually, if you want it to be null write:
mothersMaidenName = null; //mothersMaidenName doesn't have a value.
mothersMaidenName = ""; it has an empty String as value.
Don't forget the setMothersMaidenName method in order to be able to change its value.
If you remove the WHERE from the query, it won't know which record to update. And the PreparedStatement needs '?' to work in the query. As far the author field, try a new approach.
Write a class that has methods that update or do other staff with the database, and after you have tested it, use it in your .jsp. You shouldn't have too much logic in jsp files. Just html and calling methods. You shouldn't write preparedStatements and other long code calculations.
A small example of updating the db from a .jsp. (I am not saying that this will work for you)
<%
//get the parameters from the request and store them in variables
String someVariable = request.getParameter("someVariable");
//probably check the values for errors
SomeClass sc = new SomeClass();
sc.updateMethod(.......);
%>
Inside the SomeClass you should implement and TEST your queries.
I think that the concept of the query is wrong. If you want to perform an INSERT then you don't need a
WHERE ID= id
because you are inserting something that does not exist.
Perhaps you should try an UPDATE
And why did you start a new thread with the same subject mtbutt? I already gave you the same response as stultuske, and you thought that by creating a new thread no one would notice and someone else will give what you want. Did you read what I suggested to you? Try to follow it and may be you will get a better answer.
Use: double '\': '\\'
or single '/'
Put it wherever you want, as long as you say in your code where is it so you can read it:
props.load(new FileInputStream("dbConnection.properties"));
When you make changes in your .properties files, you must restart the server
I don't know these classes but from the code and the error I understand that when you are trying to do this:
ASN1Sequence asn1Sequence = (ASN1Sequence)DEROctetString;
The DEROctetString instance, is NOT an ASN1Sequence object, so it cannot be turned into one, using casting.
It is like saying something like this:
Integer integ = new Integer(10);
Date d = (Date)integ;
The toString() method MUST stay with the same name. In java, the toString() is not a method of String object but of the Object class. And you must override it in your class.
ex: when you call:
Person p = new Person(....);
System.out.println(p);
Then the system.out, automatically calls the toString() method of the class Person. If you haven't implementd it in Person then it calls the toString() of the super class, which in this case is the Object class. So if you are to implement a method that returns a String with the values of the class then you should call it toString().
The rest are correct.
You should add set, get methods for mothersMaidenName variable.
I think it will also be necessary to add it as an argument at your constructor.
public Person(String first, String family, String ID, int birth, String mothersMN ) {
givenName = first;
familyName = family;
IDNumber = ID;
birthYear = birth;
//mothersMaidenName = "";
mothersMaidenName = mothersMN ;
//This is adding the maiden name value that was requested from the assignment
}
About the last I am not sure if this is what your assignment says that you must do.
And as personal opinion, (you can do whatever you want) I would keep ID as String. I use int only if I intend to do some addition, subtractions or multiplication with the variable. Since you will not do these things with ID I would leave it String …
A nice capuccino, while watching the snow from my window.
case 5:
z=m5*Quantity;
total += z;
count++;
break;
}
total += z;
count++;
JOptionPane.showMessageDialog(null,"The total Retail Price is "+total,"RESULT",
JOptionPane.INFORMATION_MESSAGE);
}
if(choice==-1){
total +=choice;
count++;
JOptionPane.showMessageDialog(null,"The total Retail Price is "+total,"RESULT",
JOptionPane.INFORMATION_MESSAGE);
}
First red: why do you add the total again, when you have already added it inside the switch.(You don't need count either).
Second red: why do you add the 'choice' to the total. You already have the total calculated inside the while() { }. choice has the value of -1, so you are adding -1 to the total?!?!
We'll be happy to help anyone by giving ideas for their algorithm or debuging some part of the code, but don't expect for someone to read your entire code in order to figure out what is wrong when you the only comment you have made is saying that the code is messed up. What was the part that didn't work? Was it a problem with the logic or a gui problem concerning the applet? These are two separate things and you must first check that one of these works before trying putting them together.
The method Math.random() returns a random double between 0 and 1.
0 < Math.Random <1;
So one variation of jwenting's post :
private int diceRoll() {
double r=Math.Random();
//do stuff
return /* An [U]int[/U] number between 1 and 6 */
}
Try something like this:
double[] getBubbleSort(double[] values) {
double [] newArray = new double[values.length];
for (int i=0;i<values.length;i++) {
newArray[i] = values[i];
}
//your code here
return newArray;
}
A stroudel with ham and cheese cream
Are you using the KeyListener or the ActionListener? If you want the input to be from the keyboard then I wouldn't use JButtons.
What I don't understand is that when he says:
(a2+b2+1)/(ab)
Does he mean: (a*2+b*2+1)/(a*b)?
I don't if this is correct but what I did once, was to read the file line by line(like you read any other text file). You will get numbers. These numbers represent the RGB values. They are from 0 - 16777216 (256*256*256).
They are different packages with different classes. If you want a class that is inside java.package then import java, or else import javax.
Sorry about my reply and sorry about the way I talked. I was not in the right mood when I was answering, I had a problem with something else and I wasn't very calm. Sorry again and I will be nicer next time.
If it cannot locate the CompanyTrucker, just imported. And if you cannot figure that out then why are you trying to create a GUI when you don't even know the simple stuff about importing and declaring packages and classes.
for (int i=0; i <theProducts.length; i++)
{
//get the name of the i-th product
product=theProducts[i].getName();
//get the amount of the i-th product
amt=theProducts[i].getAmount();
//get the price of the i-th product
unitPrice = theProducts[i].getPrice();
//calculate the total for the i-th product
index=i;
total = amt * unitPrice;
ttl = String.valueOf(total);
// put the name and the total in the list
list1.addItem(product + " " + ttl);
// (use addItem-method of List)
}
//put total of all product in the list
theProducts[index].sumTotal(total);
finalTot = theProducts[index].getFinalTotal();
finalSum = String.valueOf(finalTot);
list1.addItem(finalSum);
Shouldn't be a sum = sum + total inside the for-loop. Each product is a different object.
when you write: theProducts[index].sumTotal(total); outside of the loop you are just calling the last object's product sumTotal with the value that 'total' had for last.
You are declaring total twice:
double total; //declarations of the neccesary variables
int amt;
double unitPrice,sum;
String product;
String ttl;
int index=0;
double total=0;
what were the errors, at which line and where is the code with the so called errors? If you say you have something like missing variable I think it is because I told you to declare you constructors with arguments so one page will know where to go next and you use empty constructors:
I didn't read all of the code but if this is where you are opening the other window then:
public void actionPerformed(ActionEvent e)
{
setVisible(false);
PerMileWindow window = new PerMileWindow(this);
//the constructor of PerMileWindow will have to change of course.
//you should add a CompanyTrucker attribute in your PerMileWindow class
}
public class PerMileWindow extends JFrame
{
CompanyTrucker trucker=null;
//the rest or you declarations
public PerMileWindow(CompanyTrucker ct) {
trucker = ct;
//the rest of your code
}
}
In PerMileWindow class:
//code for exit button handler
public class btnExitHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
this.setVisible(false);
trucker.setVisible(true);
}
}
Try adding a System.out.println(); before the JOptionPane to see where the program stops
If this is what you want to enter: John Smith, then try inserting
"John Smith"
By the way you don't say what exactly is you problem and what you are trying, to do. Post your inputs, what it is stored in the variable and what you wanted to be stored
When you press close you have to call the setVisible(true) of the original Menu Window and the setVisible(false) of the add record window. Probably you don't have access to the Menu Window from the add window. Try this
In the Menu Window when you call add-window, have it take as parameter this Menu Window
I don't khow you cod but this is how I do it:
Assume you have the two classes and constructors:
MenuWindow mw = new MenuWindow();
and
AddWindow aw = new AddWindow();
Try implemeting sth like this:
MenuWindow mw = new MenuWindow(AddWindow addW);
and
AddWindow aw = new AddWindow(MenuWindow menuW);
So in Menu when you click add new record:
AddWindow aw = new AddWindow(this);
this.setVisible(false);
And in add window when you close:
menuW.setVisible(true); //whatever variable you are using
this.setVisible(false);
Put in ONE class (ManipulateGymUser) everything non static. One empty Constructor. An ArrayList instance where you have now.:
class ManipulateGymUser {
ArrayList<GU> userList = new ArrayList<GU>();
public ManipulateGymUser() {
}
}
Add in this class every method you need that manipulates this list. They don't require an ArrayList as arguments. They already have one declared in the class.:
public void addMember() {...} accesses the declared ArrayList
public boolean alreadyExists(GymUser user) {...} accesses the declared ArrayList
And in the main create ONE instance of ManipulateGymUser
ManipulateGymUser mgu = ManipulateGymUser();
...
//printMenu or whatever
...
//when you select the option for adding:
mgu.addMember();
Just because you have already everything in other classes static doesn't mean that it is better to continue writing bad code declaring other method static too.
Why are reading these posts if you are not following our suggestions? Didn't I tell you to do this in you main:
ManipulateGymUser mgu = ManipulateGymUser();
...
...
mgu.addMember();
You have declared a Constructor, but you are not using. You are passing a parameter to it, which is used in alreadyExists() (The UserList that it is used in the alreadyExists is the one of the constructor, but you keep using the static methods) .
And inside the alredyExists you have one '=', it needs '=='
When you are calling addMember, you are inserting the new user inside the arrayList that you pass as argument, but the alreadyExists method checks the arrayList that you have declared in your class. Meaning you are adding in one arrayList nad checking another:
Remove ALL static declarations.
The constructor must be empty with no argument. You are declaring an array list at the beging of you class.
The addMember does not need an argument either. You already have a arrayList in you class.
import java.io.*; // required for handling the IOExceptions
import java.util.*;
class ManipulateGymUser
{
// create an empty list to hold Cars
ArrayList<GymUser> UserListIn = new ArrayList<GymUser>();
public ManipulateGymUser ()
{
}
// method for adding a new member to the list
public void addMember()
{
String tempUserrID;
String tempID = null;
String tempName = null;
String tempSurname = null;
int tempAge='0';
String tempAddress=null;
int tempPhone = '0';
String tempDuration = null;
//Read from the keyboard and add the values to the above varaibles
Scanner keyboard = new Scanner(System.in);
keyboard.useDelimiter("\n");
System.out.println("Please enter the member's Personal Details");
System.out.println("-------------------- ");
System.out.println("Enter the mebership number");
tempUserrID = keyboard.next();
System.out.print("Enter the ID no.: ");
tempID = keyboard.next();
System.out.print("Enter Name: ");
tempName = keyboard.next();
System.out.print("Enter Surname:");
tempSurname = keyboard.next();
System.out.print("Enter Address:");
tempAddress = keyboard.next();
System.out.print("Enter Age:");
tempAge = keyboard.nextInt();
System.out.print("Enter Phone:");
tempPhone = keyboard.nextInt();
System.out.print("MemberShip Duration:");
tempDuration = keyboard.next();
GymUser newGymUser = new GymUser(tempID, tempName, tempID, tempSurname, tempAddress, tempPhone, tempAge,tempDuration);
// primary key.
boolean b = alreadyExists(newGymUser );
if …