java,sql
Hello sir,iam sireesha studying MCA.I want a project code on JDBC,ODBC connection to display student administration system (or) student information system (or) college administraion system.Please send me the code sir,its very urgent.......
View Answers
October 7, 2010 at 11:20 AM
Hi Friend,
Try the following code:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
class StudentInformation{
JFrame f;
JPanel p1,p2,p3,p4;
JTabbedPane tp;
ImageIcon btnimg1,btnimg2;
JLabel l1, l2, l3, l4,l5,l6,l7,l8,l9,l10,l11;
JTextField tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8,tf9,tf10,tf11;
JScrollPane sp1;
JButton savebtn,resetbtn,editbtn1,editbtn2,viewbtn,delbtn ;
StudentInformation(){
f=new JFrame("Form");
p1=new JPanel(new GridLayout(5,2));
p2=new JPanel(new GridLayout(5,2));
p3=new JPanel(new GridLayout(2,2));
p4=new JPanel(new GridLayout(2,2));
tp=new JTabbedPane();
l1=new JLabel("Student ID:");
l2=new JLabel("First Name:");
l3=new JLabel("Last Name:");
l4=new JLabel("Address:");
l5=new JLabel("Enter Employee ID to view Record:");
l7=new JLabel("Student ID:");
l8=new JLabel("First Name:");
l9=new JLabel("Last Name:");
l10=new JLabel("Address:");
l11=new JLabel("Enter ID:");
tf1=new JTextField(12);
tf2=new JTextField(12);
tf3=new JTextField(12);
tf4=new JTextField(12);
tf5=new JTextField(12);
tf6=new JTextField(12);
tf7=new JTextField(12);
tf8=new JTextField(12);
tf9=new JTextField(12);
tf10=new JTextField(12);
tf11=new JTextField(12);
savebtn=new JButton(" Add ");
resetbtn=new JButton(" Reset");
editbtn1=new JButton(" Edit ");
editbtn2=new JButton(" Save");
viewbtn=new JButton("view");
delbtn=new JButton("Delete");
p1.add(l1);
p1.add(tf1);
p1.add(l2);
p1.add(tf2);
p1.add(l3);
p1.add(tf3);
p1.add(l4);
p1.add(tf4);
p1.add(savebtn);
p1.add(resetbtn);
p2.add(l7);
p2.add(tf7);
p2.add(l8);
p2.add(tf8);
p2.add(l9);
p2.add(tf9);
p2.add(l10);
p2.add(tf10);
p2.add(editbtn1);
p2.add(editbtn2);
p3.add(l5);
p3.add(tf5);
p3.add(viewbtn);
p4.add(l11);
p4.add(tf11);
p4.add(delbtn);
resetbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
}
});
October 7, 2010 at 11:21 AM
continue..
savebtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String value1=tf1.getText();
String value2=tf2.getText();
String value3=tf3.getText();
String value4=tf4.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");
PreparedStatement st=con.prepareStatement("insert into student(id, FirstName,LastName,Address) values(?,?,?,?)");
st.setString(1,value1);
st.setString(2,value2);
st.setString(3,value3);
st.setString(4,value4);
st.executeUpdate();
JOptionPane.showMessageDialog(p1,"Data is successfully inserted into database.");
con.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(p1,"Error in submitting data!");
}
}
});
viewbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
JTextField text1,text2,text3,text4;
JLabel label1,label2,label3,label4;
JPanel panel;
text1=new JTextField();
text2=new JTextField();
text3=new JTextField();
text4=new JTextField();
label1=new JLabel("ID");
label2=new JLabel("First Name");
label3=new JLabel("Last Name");
label4=new JLabel("Address");
panel=new JPanel(new GridLayout(4,2));
String value1=tf5.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");
PreparedStatement st=con.prepareStatement("Select * from student where id=?");
st.setString(1,value1);
ResultSet rs=st.executeQuery();
while(rs.next()){
text1.setText(Integer.toString(rs.getInt(1)));
text2.setText(rs.getString(2));
text3.setText(rs.getString(3));
text4.setText(rs.getString(4));
}
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(label3);
panel.add(text3);
panel.add(label4);
panel.add(text4);
JFrame frame=new JFrame();
frame.add(panel);
frame.setSize(300,200);
frame.setVisible(true);
con.close();
}
catch(Exception exp3){}
}
});
editbtn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String value=tf7.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");
PreparedStatement st=con.prepareStatement("select * from student where id=?");
st.setString(1,value);
ResultSet res=st.executeQuery();
res.next();
tf7.setText(Integer.toString(res.getInt(1)));
tf8.setText(res.getString(2));
tf9.setText(res.getString(3));
tf10.setText(res.getString(4));
con.close();
}
catch(Exception e){
JOptionPane.showMessageDialog(p2,"Can not edit data");
}
}
});
October 7, 2010 at 11:21 AM
continue..
editbtn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
try{
int x=JOptionPane.showConfirmDialog(p2,"Confirm edit? All data will be replaced");
if(x==0){
try{
String value1=tf7.getText();
String value2=tf8.getText();
String value3=tf9.getText();
String value4=tf10.getText();
int id=Integer.parseInt(value1);
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");
Statement st=con.createStatement();
st.executeUpdate("update student set FirstName='"+value2+"', LastName='"+value3+"', Address='"+value4+"' where id="+id+"");
JOptionPane.showMessageDialog(p2,"Updated successfully");
con.close();
}
catch(Exception ex){
JOptionPane.showMessageDialog(p2,"Error in updating edit fields");
}
}
}
catch(Exception ex){
JOptionPane.showMessageDialog(p2,"Error");
}
}
});
delbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String value1=tf5.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:access");
PreparedStatement st=con.prepareStatement("DELETE FROM student WHERE id = ?");
st.setString(1,value1);
st.executeUpdate();
JOptionPane.showMessageDialog(p3,"Record is deleted successfully.");
con.close();
}
catch(Exception exp3)
{
JOptionPane.showMessageDialog(p3,"Error in deleting record.");
}
}
});
}
void dis(){
f.getContentPane().add(tp);
tp.addTab("View Record",p3);
tp.addTab("Add Record",p1);
tp.addTab("Edit Record",p2);
tp.addTab("Delete Record",p4);
f.setSize(450,180);
f.setVisible(true);
f.setResizable(true);
}
public static void main(String z[]){
StudentInformation pro=new StudentInformation();
pro.dis();
}
}
October 7, 2010 at 6:49 PM
Thank you very much for sending the required code which is suitable to my question.But you din't send the backend queries i.e sql queries.But its ok for me,i can manage myself.
Related Tutorials/Questions & Answers:
Java sql ExceptionJava sql Exception difference between
sql exception class and
sql warning class
Java to SQL Server ConnectivityJava to
SQL Server Connectivity Hi, heres my code
private void bookedButton()
{
try
{
Class.forName... with
sql server connectivity at the background to save the data.
Now, after
Advertisements
java and sql server NOT Mysql - JSP-Servletjava and
sql server NOT Mysql Hi guys.
Thank you all for the various helps you render to everyone. Please the question I asked the last time... image from MS
SQL server NOT MySQL. Or is it not possible to do it in MS
SQL server
java,sqljava,sql Hello sir,iam sireesha studying MCA.I want a project code on JDBC,ODBC connection to display student administration system (or) student information system (or) college administraion system.Please send me the code sir
java - SQLjava hi .
i am asifa and i for the last few days i was trying to display the backend fields to the frontend ,am using
sql as the backend am using ecclipseeuropa IDE .can u please send the code for displaying the backend fields
java,sqljava,sql Hello sir,iam an MCA student.I want a project code of jdbc,odbc connection for educational details of a student.please send me the code. you din't send me the reply,please send it fastly sir
java,sqljava,sql Hello sir,iam sireesha studying MCA.i want a project on educational details of a student by using jdbc,odbc connection including
sql queries.please send me the reply. Hi,
Please visit http://roseindia.net
JAVA to SQLJAVA to SQL package abhijeet;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import...;
}
}
plzzz help mw wid dis...
1: i hav read and Excel file in
java java .sqljava .sql where are the interfaces of java.sql like STATEMENT,CONNECTION are defined
java,sql - JSP-Servletjava,sql Hi Amardeep,
Thank you from the bottom of my heart for giving me some excellent well thought out code.
Can you please... any appreciable result. Unfortunately, my
java coding skills are not as sharp
java sql - JSP-Servletjava sql I need to diplay only 10 records per page from my resultset.
while(rs.next())loops through entire rs. How can I use a for loop in conjunction with the while loop to display only 10 records per page and then continue
Java and SQL - SQLJava and SQL i have a problem with regard to connecting my
java code in getting a data to
SQL. my problem is on how to come up with a pop up alert message in the user interface where in the message will be coming from the
SQL java-sql - JDBCjava-sql how to convert excel file into
sql database usin
java programming
Introduction To Hibernate 4.0 map data types of
Java to
SQL data types...Hibernate is a Object-relational mapping (ORM) tool for
Java. It was initiated by Gavin King in 2001. ORM methodology is used to map classes to tables, class
questionquestion Dear Sir,
could you please send me a simple example of
java and database connectivity with
java and
sql
Please visit the following link:
JDBC Tutorials
createdatabase - SQLcreatedatabase hello
please help me...
I'm a student and I want to create database using
SQL how I can Connect
java with
SQL.
thanks Hi Friend,
Please visit the following link:
http://www.roseindia.net/jdbc
SQL connection error in androidSQL connection error in android hi,
i am android developer . recently i made one application connect with
sql server 2005 using jtds lib.application run android2.2,2.3 but run in android4.0.3 it give exception:
java convert yyyy-mm-dd hh mm ss to date in sql-mm-dd hh mm ss to date in
sql?
Thanks
Hi,
You should use following code in
SQL
DATE_FORMAT(STR_TO_DATE(my_date, "%Y/%m/%d %H:%i:%s.%f"), "%Y-%m-%d %H:%i:%s")
Thanks
Hi,
Check
SQL tutorials to learn
java SQL need projectneed project hi im new on this site so dnt knw actual procedure . but i need a project on banking system in
java with
sql database. which should contain following attributes
create new account for new customer
retrieve
Writing First Hibernate Code Mapping and Transparent Object Persistence for
Java and
SQL
Databases), we can... - org.hibernate.dialect.PostgreSQLDialect
Mckoi
SQL - org.hibernate.dialect.MckoiDialect
Microsoft
SQL... the Plain Old
Java Objects (POJOs) classes to map to the database
table. We can
JDBCTutorials up the process. Yet searches on such terms as "
Java SQL framework" and "JDBC... is to provide an introduction to the JDBC interface for connecting
Java programs with
SQL-based databases. The course is interwoven with flexible exercises
Complete Hibernate 4.0 Tutorial (ORM) tool for
Java. It was
initiated by Gavin King in 2001. ORM methodology... and attributes are mapped
to table columns. It also map data types of
Java to
SQL data types.
Hibernate is a persistence framework which used to store
Accessing database from JSP with the
Java sql.
"con" is a Connection type object variable that will hold...;
1.
Java
I/O
Tim Ritchey
2.
Java & XML,2 Edition