delgal01na

Untitled

Jul 18th, 2017
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. package karan1;
  2. import java.sql.*;
  3. import java.util.Scanner;
  4. import java.util.Vector;
  5.  
  6. public class Update {
  7. int clg_code,contact_no,mark;
  8. String name,semester;
  9. private void update(int usn,Integer clgCode, Integer contact,String Sname,String sem,Integer marks )
  10. {
  11.  
  12. try{
  13. Connection con=Jdbc1.getConn();
  14. String selectSql="Select * from student where usn=?";
  15. PreparedStatement stat1=con.prepareStatement(selectSql);
  16. stat1.setInt(1,usn);
  17. ResultSet result=stat1.executeQuery();
  18. String sql="Update student set CLG_CODE=?,CNTCT_NO=?,SNAME=?,SEM=?,MARKS=? where USN=? ";
  19.  
  20.  
  21. PreparedStatement stat=con.prepareStatement(sql);
  22.  
  23. while(result.next())
  24. {
  25. clg_code=result.getInt(2);
  26. contact_no=result.getInt(3);
  27. name=result.getString(4);
  28. semester=result.getString(5);
  29. mark=result.getInt(6);
  30. }
  31.  
  32. if(clgCode!=null)
  33. stat.setInt(1,clgCode);
  34. else
  35. stat.setInt(1,clg_code);
  36. if(contact!=null)
  37. stat.setInt(2,contact);
  38. else
  39. stat.setInt(2,contact_no);
  40. if(Sname == null)
  41. stat.setString(3,name);
  42.  
  43. else
  44. stat.setString(3,Sname);
  45.  
  46.  
  47. if(sem!=null)
  48. stat.setString(4,sem);
  49. else
  50. stat.setString(4,semester);
  51. if(marks!=null)
  52. stat.setInt(5,marks);
  53. else
  54. stat.setInt(5,marks);
  55.  
  56. stat.setInt(6,usn);
  57. int res=stat.executeUpdate();
  58. if(res>0)
  59. System.out.println("Done");
  60. else
  61. System.out.println("Problem");
  62. }
  63. catch(SQLException e)
  64. {
  65. e.printStackTrace();
  66.  
  67. }
  68. catch(Exception e)
  69. {
  70. e.printStackTrace();
  71. }
  72. }
  73.  
  74. public static void main(String[] args) {
  75. // TODO Auto-generated method stub
  76. Vector<Object> values=new Vector<Object>();
  77. Update update=new Update();
  78. update.update(54,900,null,null,null,100);
  79.  
  80. }
  81.  
  82.  
  83. }
Add Comment
Please, Sign In to add comment