Java Database Connection
Here is the Java Programming Program of Database Connection with SQL of Miss Aisha Khan.Note : This is Program not Presentation or PDF Kindly Understand the code and Work. Can Ask Anytime for help.
JavaForm: Make 2 textboxes and 3 button for Insert,Update and Delete
Insert Button
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:s1", "sa", "aptech");
Statement s = conn.createStatement();
int id=Integer.parseInt(Id.getText());
String name = Name.getText();
s.execute("insert into student values('"+id+"','"+name+"')");
System.out.println("Recond Inserted");
}
catch(Exception e){
System.out.println(e);
}
Update Button:
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:s1", "sa", "aptech");
Statement s = conn.createStatement();
int id=Integer.parseInt(Id.getText());
String name = Name.getText();
s.execute("update student set std_name='"+name+"' where std_id='"+id+"'");
System.out.println("Row Updated");
}
catch(Exception e){
System.out.println(e);
}
Delete Button:
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:s1", "sa", "aptech");
Statement s = conn.createStatement();
int id=Integer.parseInt(Id.getText());
String name = Name.getText();
s.execute("delete from student where std_id='"+id+"'");
System.out.println("Row Deleted");
}
catch(Exception e){
System.out.println(e);
}
0 comments:
Post a Comment