October 9, 2009 at 10:23 AM
Hi Friend,
Try the following code:
import java.sql.*;
import java.io.*;
import java.util.*;
class Student{
public int id;
public String name;
public Student(){}
public Student(int id, String name) {
super();
this.id = id;
this.name = name;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
}
public class RegistrationSystem {
public static void main(String[] args) throws Exception {
List<Student> list = new ArrayList<Student>();
list.add(new Student(1, "A"));
list.add(new Student(2, "B"));
list.add(new Student(3, "C"));
list.add(new Student(4, "D"));
Scanner scan = new Scanner(System.in);
int menu = 0;
System.out.println("School Registration System Main Menu");
System.out.println();
System.out.println("1. Add a student");
System.out.println("2. Remove a student");
System.out.println("3. Display student list");
System.out.println("4. Exit");
boolean quit = false;
do{
System.out.print("Please enter your choice: ");
menu = scan.nextInt();
System.out.println();
switch(menu) {
case 1:
System.out.print("Enter student ID: ");
int ID = scan.nextInt();
System.out.print("Enter your name: ");
String name= scan.next();
list.add(new Student(ID,name));
for (Student s : list){
System.out.println(s.getId()+" " +s.getName());
}
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:
mysql://localhost:3306/register","root","root";);
Statement st=con.createStatement();
int i=st.executeUpdate("insert into student values('"+ID+"','"+name+"')");
}
catch(Exception e){}
break;
case 2:
System.out.print("Enter Student id to remove the student from list: ");
int id = scan.nextInt();
int i=id-1;
list.remove(i);
break;
case 3:
System.out.println("Id Name");
for (Student s : list){
System.out.println(s.getId()+" " +s.getName());
}
break;
case 4:
quit = true;
break;
default:
System.out.println("Invalid Entry!");
}
}
while (!quit);
}
}
Thanks
Related Tutorials/Questions & Answers:
save switch data into database - Java Beginnerssave switch data into database
switch(menu) {
case 1://add a student
System.out.print("Enter student ID: ");
int ID = scan.nextInt...();
switch(menu) {
case 1:
System.out.print("Enter student ID: ");
int ID
Advertisements
save data in excelsave data in excel hello sir,
i'm new to this field i want to know can i
save data in excel by html forms input,means if any one fill up form online then it is
save offline in excel how can i do it can you give me solution sir
save data in excelsave data in excel hello sir,
i'm new to this field i want to know can i
save data in excel by html forms input,means if any one fill up form online then it is
save offline in excel how can i do it can you give me solution sir
save data DAOsave data DAO how to
save data in db
package com.tcs.ignite.dao;
import com.tcs.ignite.bean.User;
import com.tcs.ignite.connection.Connectiondetails;
import java.sql.ResultSet;
import java.sql.SQLException;
import
How to save data - Swing AWTHow to
save data Hi,
I have a problem about how to
save data ,but
first before
data save to dababase,
data must view in jLisit or Jtable...
save data from jList and Jtable(in jList or jTable
data will be many).Thank's
How do I switch to data science career?How do I
switch to
data science career? Hi,
I am beginner in
Data...:
How do I
switch to
data science career?
Try to provide me good examples or tutorials links so that I can learn the
topic "How do I
switch to
data To save table format data in pdf/excel in jspTo
save table format
data in pdf/excel in jsp Hello,
I am doing web application project in jsp. In webform ,I am displaying
database data in html table. So my question is ,I want so
save this html format
data in pdf/excel format
Save JRadioButton Text in to database - Java BeginnersSave JRadioButton Text in to
database Hello Sir I have Two JaradioButtons
1)Semwise Course
2)Yearwise Course
I want To
Save Text from...();
JOptionPane.showMessageDialog(null,"
Data is successfully inserted into
database.");
}
catch
how to show data in database ?how to show
data in
database ? how to show the
data in the
database to the user in the textbox so that user can modify it and
save it again
Insert image from user using and save in databaseInsert image from user using and
save in database when i am trying to upload a image from user and trying to
save into oracle9i
database....
Apache Tomcat/6.0.29 We have used MySQl
database.
1)page.jsp:
<
SQL database parameters should save at where?SQL
database parameters should
save at where? Hi,
Currently... the script will be running for very long time,
I like to move the SQL
database..., if there is a
database changed (hostname, username or password)
It should
code save word file in 10g database - SQLcode
save word file in 10g database I am not having any idea to
save the whole word document in Oracle 10g. Please help me. Hi Friend...(file);
pstmt = conn.prepareStatement("insert into file( file, file_
data Save the input data until user get changedSave the input
data until user get changed I would like to know how to store the give input
data and perform the calculations even after re-opening... and
save this amount until he changes it again.
Thank You
Save the input data until user get changedSave the input
data until user get changed I would like to know how to store the give input
data and perform the calculations even after re-opening... and
save this amount until he changes it again.
Thank You
Save the input data until user get changedSave the input
data until user get changed I would like to know how to store the give input
data and perform the calculations even after re-opening... and
save this amount until he changes it again.
Thank You
How can we save a data list in jsf?How can we
save a
data list in jsf? I have a code in jsf that fires a query in
Data Base each time it is called, i have added a validation check... it is called again. I tried using
save State but it did not help as other functions got
database data in xml formatdatabase data in xml format HI,
i want to display the
database data in the xml format(not as xml file ) on the console using DOM. help will be appreciated.
THANKS
K.K
SQLGrammarException while trying to save data in dbSQLGrammarException while trying to
save data in db //hibernate cfg file//
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN
retrive data from database?retrive
data from
database? hellow
i have a
database sheet name as db1. it's contain sixty(60) sn,name ,rollno(primary key),father's name etc... from db1 and enter value in text box according there name,rollno and
save insert and delete data in databaseinsert and delete
data in database insert and delete
data in
database from servlets through JDBC
Hi Friend,
Please visit the following links:ADS_TO_REPLACE_1
Insert
Data
Delete
Data
ThanksADS_TO_REPLACE_2
Retriving data stored in databaseRetriving
data stored in database Hi,
How to retrive
data from my sql
database using Hibernate,Spring and tapestry please give me an example.I am new to this Hibernate and Spring
Saving data in databaseSaving
data in database hello
i m facing a strange problem if i am submitting
data form
database then i can see it in
database
but if am submitting from app then it is not showing in to
database but when i fetching form
selecting data from databaseselecting
data from database how to select
data from
database using Dao in struts
Hi,
You have to load the
data from
database using hibernate and send the
data in a Java file object to jsp page.ADS_TO_REPLACE_1
Transfer Data to Sql DatabaseTransfer
Data to Sql Database Hey guys, how to
Transfer
data to SQl
database using Java?
Transfer
data already stored in excel to Sql databse using Java?
Looking for an easier method so i can comprehend
retrive data from database retrive
data from
database hi..
i made a application form. it's have attribute s.no,name,roll no and i enter a few records. now i want to view all record not in
database access sheet i want to view it at any another
insert data into databaseinsert
data into database hi,thanks for reply
just i am doing... and studentmaster is the
database table name.
i am using same details.
Now give the
data into the jsp page that
data stored into the database.Here the error
Java save file to databaseJava
save file to
database
In this section, you will learn how to insert file to
database.
Description of code:
Firstly, we need to establish a connection between MySql
database and java
file with the help of various types of APIs
unable to insert data into database unable to insert
data into
database hello.i have a problem in inserting
data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting
data into
database based
unable to insert data into database unable to insert
data into
database hello.i have a problem in inserting
data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting
data into
database based
unable to insert data into database unable to insert
data into
database hello.i have a problem in inserting
data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting
data into
database based
unable to insert data into database unable to insert
data into
database hello.i have a problem in inserting
data into database.i have used two prepared statement.one for retrieving the eid based on ename and the other is inserting
data into
database based