Try to add some System.out.println in the readFile method and see what happens. Also you need to declare the list as a private member of the class like filePath. With your way, you create it in the method readFile and then after it executes, you have lost it, you cannot access it

[QUOTE=poojavb;1757567]Check if the connection is created to the database
[CODE]
Connection con;
Statement stmt=con.createStatement();
ResultSet rs=null;

String ss=("SELECT VIDEOID, VIDEONAME, DIRECTOR FROM VIDEOS");
rs=stmt.executeQuery(ss);
while(rs.next())
{
//code goes here
}
[/CODE][/QUOTE]

That is not what [I]TIM_M_91[/I] has asked.

@TIM_M_91:
It is odd that you haven't found the correct syntax because all you needed is some basic tutorials about sql: [url]http://w3schools.com/sql/default.asp[/url]
Any way, you can add this to your query:
[CODE]
SELECT VIDEOID, VIDEONAME, DIRECTOR
FROM VIDEOS
WHERE VIDEOID=[I]something[/I] AND VIDEONAME=[I]somethingelse[/I] ...
[/CODE]
Instead of AND you can use OR

The columns that you use as filters don't need to be at the select. This query is valid for example:
[CODE]
SELECT VIDEONAME
FROM VIDEOS
WHERE VIDEOID=[I]something[/I]
[/CODE]

If you want to put it in java, using the Statement interface (as in your code) you can try this:
[CODE]
String videoId = "some_value";

String ss="SELECT VIDEOID, VIDEONAME, DIRECTOR FROM VIDEOS";
ss += " WHERE VIDEOID='"+videoId+"'";

System.out.println("Executing query:"+ss);

rs=stmt.executeQuery(ss);
[/CODE]

What's out for the single quotes ' . The value of the ss is the query executed so print it and see what you have.

[QUOTE=rushikesh jadha;1752767]you can catch array index out of bound exception.[/QUOTE]

Never use try-catch for ArrayIndexOutOfBoundsException. You already know at runtime the size or length of what you are trying to use. So always check that.

long89:
So when looping, it is good to do this instead of what you have:
[CODE]
for (int i=0;i<people.length;i++) {
// use people[i]
}
[/CODE]

commented: agreed. avoiding an indexoutofboundsexception is way better than handling it. +14

You can load the servlet directly. Instead of writing at the url:
[url]http://localhost:port/index.jsp[/url]

you can write:
[url]http://localhost:port/YourServlet[/url]

I am sorry to tell you this, but if you are a beginer with java why do you write jsps? The code that you wrote has several errors, but not because of your lack of effort. Because there some things that you have confused and you need some studying to do first before start writing. The code will not work the way you "imagine" that it will work. You write html and javascript and assume that it will behave like java does:

<INPUT NAME="GIRL">
That is not how you declare variables in html and you cannot reference it like this:
document.write ("Take "GIRL" to the "PLACE" on "DAY);
because there aren't any variables in html that you can call at "runtime"

The function PickDate is written in javascript and you are trying to call java methods in it.

You are trying to write html as if you are writing java in a main method.

From your code one can understands that you have confused a lot of things about the differences between java - html - jsp - javascript and it will not help you learn if someone just writes it for you.

As hiddepolen stated - while I was preparing this post - what you are trying to do can be done with pure javascript. You need to declare the html tags correctly and use the apropriate javascript in the PickDate. You are also trying to use java in the html withour java scriplets.

In general you should stick ...

The encryption takes place in the servlet not when you submit the page. You pass the password the user entered from the gui, so the password at the url is unencrypted. It goes to the servlet where you do the encryption.

There is no way to avoid that. (Actually there is but it is needless).
What people do is use:
[CODE]
<form name="form1" method="POST" action="LoginServlet" onsubmit="return checkForm()">
[/CODE]

method="POST"

[QUOTE=peter_budo;1677430]Embedded [URL="

Have the [ICODE]System.out.println("Number of tosses\t\tNumber of Heads\ % \t\tNumber of Tails\ %");[/ICODE] before the loop.

Loop 500 hundred times. Every 30 times, print the
[ICODE]System.out.printf("\t%d\t\t\t\t%d %d\t\t\t\t%d %d", frequencyHeads + frequencyTails,frequencyHeads,percentageH, frequencyTails,percentageT);[/ICODE]
in the loop

You don't call the actionperformed. It is automatically called whenever you click a button.
You implement it normally in the same way you do when you use javax.swing. Your applet should implement the ActionListener interface, then you will declare the actionPerformed method and write code inside it. Then you will add to your buttons that ActionListener (namely the applet like you do with normal java GUI).

If you want to call the actionPerformed method explicitely meaning you want to call the code inside in some cases, I would suggest to either call directly the code you put inside the actionPerformed method, or trigger the button clicked yourself. The JButton class has a doClick method for that purpose

Do you have any code? The assignment that you posted is actually an explanation of what you need to do:

[I]"Data fields for your instrument should include number of strings, an array of string names representing string names (e.g. E,A,D,G), and boolean fields to determine if the instrument is tuned, and if the instrument is currently playing."
[/I]

Create a class that has the above fields. Follow the instructions to create your classes and methods. You don't need to think anything.

If you have errors post your code.

[QUOTE=java.util;1656426]@javaAddict: Thanks, I tried your code and it's working! I guess the problem is solved then. I don't get why i can't have "while (tallPosisjon <= famousFinalFour.length())" though, but I'll look into it.
Thanks everyone for your help, I'll mark this as solved

@Norm: aha, of course. Well I guess it's solved now anyway.[/QUOTE]

Because when tallPosisjon = famousFinalFour.length() it will enter the loop and you will call the:
famousFinalFour.charAt(tallPosisjon);

But indexes in java are from 0 to length-1. If a String has length 4 ("abcd") you can call:
charAt(0), charAt(1), charAt(2), charAt([B][COLOR="Green"]3[/COLOR][/B]) but not charAt([B][COLOR="Red"]4[/COLOR][/B])

It like when you loop:
[CODE]
for (int i=0;i<array.length;i++) {

}
[/CODE]
You don't use <=

So you are saying that the method kjennetegnErGyldig correctly returns false when you enter wrong data but when you enter the right data the loop doesn't go to the
[ICODE]System.out.println("Årsmodell: ");[/ICODE] call ?

If yes then maybe the problem is with the kjennetegnErGyldig method. Try to add more prints at the beginning and the end. Specifically before you return true. Have you tested it? Since it is static you can call it alone from a main method and see if it returns true.

My guess is that when it enters the last loop it never exits:
[CODE]
while (tallPosisjon <= famousFinalFour.length()) {
if (! (famousFinalFour.charAt(tallPosisjon) >= '0' && famousFinalFour.charAt(tallPosisjon) <= '9') ) {
System.out.println("De fire siste sifrene må være heltall mellom 0 og 9.");
return false;
}
}
[/CODE]

Look at it. If it enters the loop you have no way to exit. The tallPosisjon will always be lower than the famousFinalFour.length. Shouldn't you be increasing the tallPosisjon with each loop, so eventually the tallPosisjon <= famousFinalFour.length will become false?
[CODE]
while (tallPosisjon < famousFinalFour.length()) {
if (! (famousFinalFour.charAt(tallPosisjon) >= '0' && famousFinalFour.charAt(tallPosisjon) <= '9') ) {
System.out.println("De fire siste sifrene må være heltall mellom 0 og 9.");
return false;
}
tallPosisjon++;
}
[/CODE]

Notice the the check should be: tallPosisjon < famousFinalFour.length without the equals. If it is equal the charAt will give you an ArrayIndexOutOfBounds Exception.
The tallPosisjon should be from 0 till famousFinalFour.length-1

[QUOTE=anand01;1636902][code]
responce .sendRedirect("user.jsp");
[/code][/QUOTE]

For single values that approach could work. You can use this:
[CODE]
String value1 = "aaaa";
String value2 = "bbbbb";

responce.sendRedirect("user.jsp?param1="+value1+"&param2="+value2);
[/CODE]
At the jsp you can use this:
[CODE]
String param1 = request.getParameter("param1");
String param2 = request.getParameter("param2");
[/CODE]
When sending data like that use the .getParameter. But that won't work if you have one instance of an object and you want to send the whole thing

If you want to send an instance of an object use this at the servlet instead of the sendRedirect
[CODE]
SomeObject obj = get_from_somewhere;
request.setAttribute("SOME_KEY", obj);

RequestDispatcher dispatcher = request.getRequestDispatcher("user.jsp");
dispatcher.forward(request, response);
[/CODE]

At the jsp:
[CODE]
SomeObject obj = (SomeObject)request.getAttribute("SOME_KEY");
[/CODE]

First, use code tags. Press the button CODE and put your code between the tags.
Also I tried running your code and it didn't work, even though it is correct. It behaves very strange and the debug gives me strange behavior. Finally I found the problem. When you write (me) something a lot of times, when you see it written you assume that it is correct, but in your case it is wrong:

I write:

for (int i=0;i<length;i++) 
{

}

You wrote:

for(ctr = 0; ctr < sentence.length(); ctr++);
{

}

Can you spot the difference:

for(ctr = 0; ctr < sentence.length(); ctr++);

We use the ';' to terminate commands. So when you put the ';' at that place you terminated the for loop. So only this got executed N times:

for(ctr = 0; ctr < sentence.length(); ctr++);

And then after ctr changed frm 0 to sentence.length() the following command executed outside the loop:

System.out.println(sentence.charAt(ctr));

So basically when you put that ';' at the end of the for loop you practically wrote something like this:

for(ctr = 0; ctr < sentence.length(); ctr++) {}
{
  System.out.println(sentence.charAt(ctr));
}

The for executes with no body. Then when the ctr is equals to sentence.length() exits the loop and executes one System.out.println(sentence.charAt(ctr)) which gives you an error.

Try running this and see what happens:

int i=0;
for (i=0;i<length;i++);
 System.out.println("i: "+i);

Then write this with no ';'

int i=0;
for (i=0;i<length;i++)
 System.out.println("i: "+i);
commented: Helpful explanation. +15

The '=' is used for assignments. The '==' is used for comparison:
[CODE]
if(Btn2.getSelected() == true){

}
[/CODE]

Or [U]better[/U] if the Btn2.getSelected() returns boolean:
[CODE]
if ( Btn2.getSelected() ){

}
[/CODE]

Edit: In your code you use Btn2.setSelected() . Perhaps you meant getSelected, because normally with set you pro-grammatically change the value

Don't use random methods. This isn't the lottery. Use logic.
Since you are writing jsps, you know how to loop an array:
[CODE]
for (int i=0;i<array.length;i++) {
[/CODE]

Why you set i to be 0 and i<length ? You pass the counter at the request and you use it as argument at the get method.
The list has elements from 0 till size-1, so the counter must be within that range. So display the next, previous links only when the value at the Counter parameter of the links is within that range

commented: One for sticking with this guy, and hard time spoon-feeding :) +16

The declaration is wrong. There is no such thing as int void.
It is either int or void. And in this case it should be int:

[CODE]
public int countTokens(String s)
{
StringTokenizer st= new StringTokenizer();
return st.countTokens();
}
[/CODE]

You should better remove the initialization of BufferedWriter outside the loop. Why you need it in? Each time you create a new one, you close it then create again a new one?
Put it outside the loop, in the loop call only the write method and close after the loop.
Understand what your code does.

So you are saying that when you debug the messages:
[U]Will read file[/U] , [U]Done reading file[/U] appear
but when you run it, only the first one appears?

I would suggest the following. More debug messages:
[CODE]
File file = new File("projects");
// print the file
// print if the file exists: file.exists()
JOptionPane.showMessageDialog(null, "Will read file", "clear.", WIDTH);
FileReader input = new FileReader(file);
JOptionPane.showMessageDialog(null, "Done reading file", "clear.", WIDTH);
[/CODE]

And at the end add another exception:
[CODE]
private void readFileButtonActionPerformed(java.awt.event.ActionEvent evt) {
try {
// ...........
} catch (ArrayIndexOutOfBoundsException e) {
/ If no file was passed on the command line, this expception is
generated. A message indicating how to the class should be
called is displayed
/
JOptionPane.showMessageDialog(null, "Unable to open Project file. (IOOB)", "Error: Contact Programmer.", );

    } catch (IOException e) {
        // If another exception is generated, print a stack trace
        JOptionPane.showMessageDialog(null, "Unable to open Project file. (IO)", "Error: Contact Programmer.", );
        e.printStackTrace();
    } 

// add this
catch (Exception e) {
JOptionPane.showMessageDialog(null, "Final error: "+e.getMessage(), "Final Error", );
e.printStackTrace();
}
}
[/CODE]
You will also need to check the console or the IDE output when you run it in order to see the printStackTrace or any other messages you print using the System.out.println

[CODE]JOptionPane.showMessageDialog(null, "Unable to open Project file. (IO)", "Error: Contact Programmer.", WIDTH);[/CODE]
The WIDTH is not correct. Just because it got auto completed from the IDE doesn't mean you should blindly follow it. Check the API of JOptionPane class and check that method ...

Firstly the requirements say that you shouldn't append the results to the new files so don't use the [B]true[/B] option:
FileWriter fstream = new FileWriter(filename,true)

Second if you have been taught to use the PrintWriter then use that.

You can use the BufferedReader to read from a file or you can also use the Scanner class. if you pass as argument to its contructor a File object.

As far as your Studnet class: JPleasant_Project#1
You have been told to create a Student class not a JPleasant_Project#1 class.
Also the name,hours,grade need to be the attributes of the class, not local methods inside of a main. Don't put a main inside the Student class. Just the attributes with get/set methods. Surely you have been taught how to create custom classes.

You will use code to write in the new files. That code would be put in the if-else statements and according to each case you will write to the file described by your requirements.
Create different writers outside the loop with the students and use their instances to write to each file.

The code provided by [I]jeffery12109[/I] was just an example. you need to make the right modifications or whatever way you have been told to use

If your teacher hasn't told you how to create custom classes then things are to become more complicated, because you need in the same main, do the reading and while reading writing to right files as well. The problem is that you will ...

[QUOTE=jpleas;1606940]Okay is there any steps you can give me to work on I know I have to create the candidates.txt, cumlaude.txt, magna.txt, summa.txt, noGrad.txt, hoursError.txt and gpaError.txt. Do I put the if statments above by name into these cumlaude.txt and what more do I need to assign to String name; double hours; double grade;... We get all this from the user so its unknown correct? I just need help. Steps, procedures, anything..[/QUOTE]

You have already been given the first steps to start at my first post.

Don't put everything in the main method and don't write everything at once.
First create a Student class with attributes: name, hours, grade.

Then have a single method:
In that method read the file with the students and have the method return a list with the data. The List will have Student objects

First write that method test it and then you can call it, loop the list and have if statements in order to determine which student to write to which new file.

Can you post the code you used?

Or you can search this forum for examples on how to run queries at a database and get the results.
Remember, put that code in a separate method in a class and call that method from wherever you want. That method should return the data you want to display.

And try to avoid roseindia

commented: +1 Good suggestion. +15

You don't need the commit command. It is done automatically, unless specified otherwise.
Also try to print the query and what actually gets executed.
Also the executeUpdate returns an int value. It shows how many rows have been updated/inserted. Try to print that too.
Also your catch block is empty. Why? That is problem. If you have an exception, you print nothing and you don't know if something went wrong.
You also need to close the connection as well as the Statement.
And it is better not to use the from.toString() . If you want to save the address, try to use: [B]from.getMailAddress()[/B] or something. Because toString is used for displaying and maybe in the future you decide you want to change the way the object gets displayed. But since you need to save in the DB only the email, then you need to get the email.

[CODE]
import java.io.;
import java.util.Properties;
import javax.mail.
;
import java.sql.*;

public static void insertm(int mid,Address from,String sub){

try {
// Load the JDBC driver

Class.forName ("oracle.jdbc.OracleDriver");

Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@//localhost:1521/xe", "scott", "tiger");

    Statement stmt = conn.createStatement();
  String str = from.toString();

System.out.println(sub+", "+str+", "+mid);
//sql
String sql = "insert into mms(subject,pno,mid) values ('"+sub+"','"+str+"',"+mid+")";

System.out.println("Executing: "+sql);    

int i = stmt.executeUpdate(sql);

System.out.println("Rows Updated: "+i);   

 stmt.close();
 conn.close();

} catch(Exception e) {
System.out.println("Error: "+e.getMessage());
System.out.println("Details: ");
e.printStackTrace();
}
[/CODE]

The next step would be to move the close commands in the finally block:
[CODE]
....
try {
....
} catch (Exception e) {
System.out.println("Error: "+e.getMessage());
} finally { ...

commented: problem solved +0
commented: finally block, +1 PreparedStatement ??? +8

[QUOTE=jamd200;1595554]Thank you for your feedback. Ok, I made it so that it takes in any number of arguments, but I kept the try-catch block just in case someone enters a non-numerical argument. [/QUOTE]

That is good thinking! But is best to user the NumberFormatException. Again with this code if you have an exception other than "the user has entered non numeric" you will display the same message. In this case, you are correct. Nothing else would be thrown.
Your code works.

But in case you don't know about the NumberFormatException it is the exception that you get when you try to call the Integer.parseInt with non numeric values.
So you could alter your code like this:
[CODE]
catch(NumberFormatException nfe) {
System.out.println("You may have entered a non-numerical argument: "+nfe.getMessage());
}
[/CODE]

And as [I]NormR1[/I] said:
Also I think that you should check that happens if the user doesn't enter any arguments. In this case, arguments will have length zero and you will have an exception when you try to divide in order to get the average.
You could add an if statement at the beginning checking if the length of the args is positive

commented: Thank you for you help. - jamd200 +1

If I may add, I don't believe that the approach of using a try-catch for handling the length of the arguments is correct:
[CODE]
catch(Exception e)
{
System.out.println("There can only be four arguments entered for this program.");
System.out.println("At the next prompt in this command line,");
System.out.println("enter 'java Test' followed by the four (and only four) arguments");
System.out.println("that you want to enter for this program.");
}
[/CODE]

In this case it is ok, but in general no. For example. With the above code you catch all the exceptions:

[ICODE]catch(Exception e) {[/ICODE]
Meaning that if some other exception happens you will still display the same message. In this case of course I don't see any other possible exception caught, but it is not correct to ignore the exception instance 'e'.

Also you should never catch exceptions that can be avoided such as ArrayIndexOutOfBoundsException. You know that this exceptions happens when you try to access arrays, but I have never seen anyone loop like this:
[CODE]
int [] array = new int[4];
try {
for (int i=0;i<1000000000;i++) {
System.out.println(array[i]);
}
} catch (ArrayIndexOutOfBoundsException e) {
}
[/CODE]

A better approach would be:

[CODE]
if (args.length!=4) {
System.out.println("There can only be four arguments entered for this program.");
System.out.println("At the next prompt in this command line,");
System.out.println("enter 'java Test' followed by the four (and only four) arguments");
System.out.println("that you want to enter for this program.");

System.exit(0);
}

int[] arguments = new int[4];
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);

..
[/CODE]

Also [I]NormR1[/I] is ...

commented: Nice details.I was too lazy. +12

Cross posted in this thread:
[URL="

[QUOTE=ssaatt;1590975]i need jsp and servlet coding for login page where the username and password must b stored in a db table[/QUOTE]

And I want vacation.
Sorry I thought that this thread was for posting what we want but [U]you won't get[/U]!

Seriously:
This thread is very old. If you have a question start your own. And no one is going to give you the code. We don't give code like that. If you don't have a clue start studying and search for examples in this forum. Post what you have done.
You need to know basic java, connecting to the database and running queries, sql, html and jsp. What do you know from the above?

And separate your methods in different classes. Don't put code that connects to the database in the jsp page.
Once you post what you have done you will get help.

I tested your code and couldn't get it to work. The buttons weren't displayed.
I would advise you not to use the paintComponent. It it used to paint graphics (circles, images, lines, ....)
You don't need that method to add buttons and other components such as JLabels

Try putting the code of the ButtonPanel in a constructor:
[CODE]
....
....
private class ButtonPanel extends JPanel
{
public ButtonPanel() {
JButton redButton=new JButton("Red");
JButton yellowButton=new JButton("Yellow");
JButton greenButton=new JButton("Green");

            add(redButton);
            add(yellowButton);
            add(greenButton);

            ColorAction setRed=new ColorAction(Color.RED);
            ColorAction setYellow=new ColorAction(Color.YELLOW);
            ColorAction setGreen=new ColorAction(Color.GREEN);

            redButton.addActionListener(setRed);
            yellowButton.addActionListener(setYellow);
            greenButton.addActionListener(setGreen);
        }
            /*
    public void paintComponent(Graphics g)
    {

    }
            */
}

....
....
[/CODE]

By using proper html. You align in the same way you would have aligned them if they weren't select tags.
Do you use table tags? If yes then there is something wrong with your td,tr tags. Try to add the border="1" attribute at the <table> and see what is going on.

[CODE]
<table border="1">
<tr>
<td>Line 1 Col 1</td>
<td>Line 1 Col 2</td>
</tr>
<tr>
<td>Line 2 Col 1</td>
<td>Line 2 Col 2</td>
</tr>
</table>
[/CODE]