Archive for the ‘Java’ Category
Deleting multiple records through Checkbox with jsp
In my project To-Do List , I had a problem about how to delete multiple records through checkbox, for that I was searching code and I got link which was very suitable for for my project. Make following code as delete.jsp
<%@ page import="java.sql.*"%>
<%
String deleteArray[] = request.getParameterValues("select");
String selected="";
if (deleteArray != null) {
if(deleteArray.length == 1) {
// Only one item is selected
selected = deleteArray[0];
} else {
// multiple items selected
for (int i = 0; i < deleteArray.length; i++) {
selected += deleteArray[i];
if( i < deleteArray.length -1) {
selected += ",";
}
}
}
}
%>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c = DriverManager.getConnection("jdbc:odbc:Task","","");
Statement st = c.createStatement();
PreparedStatement pst = c.prepareStatement("DELETE FROM tasklist WHERE task_id IN
("+selected+")");
pst.executeUpdate();
%>
If you want to know more about it,then follow this link http://forum.java.sun.com/thread.jspa?threadID=629227&messageID=3633428
Installation of Apache Tomcat Using Redhat Linux
For installation of Apache Tomcat you need Java Development kit be installed. I chose to install Sun’s Java 2 Platform, Standard Edition, which can be downloaded from http://java.sun.com/javase/downloads/index.jsp
I selected the JDK 6 Update 3 Linux self-extracting binary file.
Change to the directory where you downloaded the SDK and make the self-extracting binary executable:
chmod +x jdk-6u3-linux-i586.bin
Run the self-extracting binary:
./jdk-6u3-linux-i586.bin
Move the SDK directory to where you want it to be installed:
e.g.
mv jdk-6u3 /usr/java
Download Tomcat:
You can download apache tomcat server from http://tomcat.apache.org/. I selected Tomcat 6.x which is tar.gz (Binary- Core) file.
Unzip Tomcat by issuing the following command from your download directory:
tar xvzf apache-tomcat-6.0.14.tar.gz
This will create a directory called apache-tomcat-6.0.14. Move this directory to wherever you would like to install Tomcat. I chose /usr/local. Here is the command I issued from inside the download directory:
mv apache-tomcat-6.0.14 /usr/local/
Task Manager (To Do List)
I am going to make my T.Y.Bsc( Computer Science)’s project (Task manager) using JSP, Apache, MySQL . TaskMan is a basic, yet fully functional web-based Task Management System.
Features include:
- Task List with Search by Assigned Person
- Search Tasks by Priority
- Search Tasks by Status
- Sorting by any of the columns (Task, Project, Priority,Assigned Person, Status)
- Administration of Employees
- Administration of Priorities
- Administration of Projects
- Administration of Statuses
Number Conversion
Enter decimal number in the text field. When Calculate button clicked, It will display binary, octal and hexadecimal equivalents.
// By Santosh Wadghule.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class NumberConversion extends JFrame implements ActionListener
{
JLabel l1,l2,l3,l4,n1,n2;
JTextField tf1,tf2,tf3,tf4;
JButton b1,b2;
JPanel p1,p2;
JFrame frame;
NumberConversion () //constuctor
{
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
n1 = new JLabel("Created BY :",JLabel.CENTER);
n2 = new JLabel("Santosh Wadghule",JLabel.CENTER);
l1 = new JLabel("Decimal Number",JLabel.CENTER);
l2 = new JLabel("Binary Number",JLabel.CENTER);
l3 = new JLabel("Octal Number",JLabel.CENTER);
l4 = new JLabel("Hexadecimal Number",JLabel.CENTER);
tf1 = new JTextField();
tf2 = new JTextField();
tf3 = new JTextField();
tf4 = new JTextField();
b1 = new JButton("Calculate");
b2 = new JButton("Clear");
frame.setTitle("Number Conversion");
frame.setLayout(new GridLayout(6,2));
frame.setSize(300,300);
frame.add(n1);
frame.add(n2);
frame.add(l1);
frame.add(tf1);
frame.add(l2);
frame.add(tf2);
frame.add(l3);
frame.add(tf3);
frame.add(l4);
frame.add(tf4);
frame.add(b1);
frame.add(b2);
frame.setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
} // end designing part
public static String toBinary(int n)
{
StringBuffer s = new StringBuffer(16);
while(n!=0)
{
s.append(n%2);
n=n/2;
}
return s.reverse().toString();
}
public static String toOctal(int n)
{
StringBuffer s = new StringBuffer(16);
while(n!=0)
{
s.append(n%8);
n=n/8;
}
return s.reverse().toString();
}
public static String toHex(int n)
{
StringBuffer s = new StringBuffer(16);
while(n!=0)
{
if(n%16>=10)
s.append((char)(55+n%16));//conversion for character
else
s.append(n%16);
n=n/16;
}
return s.reverse().toString();
}
public void actionPerformed(ActionEvent ae)
{ JButton b = (JButton)ae.getSource();
if(b==b1)
{
int n = Integer.parseInt(tf1.getText());
tf2.setText(toBinary(n));
tf3.setText(toOctal(n));
tf4.setText(toHex(n));
}
if(b==b2)
{
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf1.requestFocus();
}
}
public static void main(String args[])
{
new NumberConversion();
}
}
To-do list Source code on PSC
Today, I have uploded source code of ToDoList on Planet-Source-Code sites for beginners. This is very simple code for understand so everyone can imlpement this code. You can download it from by this link
Download
To-Do List

This is simple To-do List java program. To-do List java program is just like to add item through textfield to the list. This program is created using swing.You can add and remove item from the list.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ToDoList extends JFrame implements ActionListener
{
JLabel l1,l2,l3;
JTextField tf;
JButton b1,b2;
JPanel p1,p2,p3,p4;
JFrame frame;
List lst;
ToDoList ()//constuctor
{
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
l1 = new JLabel("TO DO LIST",JLabel.CENTER);
l2 = new JLabel("",JLabel.CENTER);
l3 = new JLabel("Enter Here",JLabel.LEFT);
lst = new List();
tf = new JTextField();
b1 = new JButton("Add");
b2 = new JButton("Remove");
p1 = new JPanel();
p1.setLayout(new GridLayout(2,1));
p1.add(l1);
p1.add(lst);
p2= new JPanel();
p2.setLayout(new GridLayout(3,1));
p2.add(l2);
p2.add(l3);
p2.add(tf);
p3= new JPanel();
p3.setLayout(new GridLayout(1,2));
p3.add(b1);
p3.add(b2);
frame.setTitle("Santosh Wadghule");
frame.setSize(300,300);
frame.setLayout(new BorderLayout());
frame.add(p1,"North");
frame.add(p2,"Center");
frame.add(p3,"South");
frame.setVisible(true);
b1.addActionListener(this);
b2.addActionListener(this);
}// end designing part
public void actionPerformed(ActionEvent ae)
{
JButton b = (JButton)ae.getSource();
if(b==b1)
{
String element = tf.getText();
lst.add(element);
tf.setText("");
}
if(b==b2)
{
int i = lst.getSelectedIndex();
lst.remove(i);
lst.select(i);
}
}
public static void main(String args[])
{ new ToDoList();
}
}
Simple Function call program
This java program is very simple to understand that how one function calls to another function.
here, main function calls the santosh and anil function.
public class FunctCall
public static void santosh () {
System.out.println ("Inside the santosh fuction");
}
public static void main (String[] args) {
int val;
System.out.println ("Inside main");
santosh();
System.out.println ("About to call anil function");
val = anil(4);
System.out.println ("anil returned a value of " + val);
System.out.println ("About to call anil again");
val = anil(-2);
System.out.println ("anil returned a value of " + val);
}
public static int anil (int param) {
System.out.println ("Inside anil with param " + param);
return param * 2;
}
}
HelloDate
This java program is to show the date of month.
import java.util.*;
public class HelloDate {
public static void main (String[] args) {
System.out.println ("Hello, it's: ");
System.out.println(new Date());
}
}
Simple Java Program
public class MyFirstApp
{
public static void main ( String[] args)
{
System.out.println("Hello World");
} // main method
} // MyFirstApp class
1] public is for that everyone can access it.
2] MyFirstApp is the name of class.
3] String[] for arguments to the method. This method must be given an array of Strings,and the array will be called ‘args’.



