delgal01na

Untitled

Jul 21st, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. package org.MyStudent.Main;
  2.  
  3. import org.MyStudent.bean.Student;
  4. import org.MyStudent.dao.StudentDAO;
  5.  
  6. public class mainClass {
  7.  
  8. public static void main(String[] args) {
  9.  
  10. Student student=new Student();
  11. student.setUsn(326);
  12. student.setClg_code(11);
  13. student.setContactNo(6666);
  14. student.setSName("CASE STUDY");
  15. student.setSem(6);
  16. student.setMarks(80);
  17.  
  18.  
  19. StudentDAO s=new StudentDAO();
  20. s.save(student);
  21.  
  22. }
  23.  
  24. }
  25. -----------------------------------------------------------------
  26.  
  27.  
  28. package org.MyStudent.dao;
  29.  
  30. import java.sql.Connection;
  31. import java.sql.PreparedStatement;
  32.  
  33. import org.MyStudent.bean.Student;
  34. import org.MyStudent.conn.DbConn;
  35.  
  36. public class StudentDAO {
  37.  
  38.  
  39. public void save(Student student)
  40. {
  41.  
  42. try
  43. {
  44.  
  45. String sql="insert into student values(?,?,?,?,?,?)";
  46. Connection con= DbConn.getConnect();
  47. PreparedStatement stat=con.prepareStatement(sql);
  48.  
  49. stat.setInt(1, student.getUsn());
  50. stat.setInt(2, student.getClg_code());
  51. stat.setInt(3, student.getContactNo());
  52. stat.setString(4, student.getSName());
  53. stat.setInt(5, student.getSem());
  54. stat.setInt(6, student.getMarks());
  55.  
  56. stat.executeUpdate();
  57.  
  58. }
  59. catch (Exception e) {
  60. e.printStackTrace();
  61. }
  62.  
  63. }
  64.  
  65. }
  66. -------------------------------------------------------------------
  67.  
  68. package org.MyStudent.conn;
  69.  
  70. import java.sql.Connection;
  71. import java.sql.DriverManager;
  72.  
  73. public class DbConn {
  74.  
  75.  
  76. public static Connection getConnect()
  77. {
  78. try
  79. {
  80.  
  81. Class.forName("oracle.jdbc.OracleDriver");
  82. Connection connection=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","tiger");
  83. return connection;
  84. }
  85. catch (Exception e) {
  86. return null;
  87. }
  88. }
  89.  
  90. }
  91.  
  92.  
  93. ------------------------------------------
  94.  
  95. package org.MyStudent.bean;
  96.  
  97. public class Student {
  98.  
  99. int Usn;
  100. int Clg_code;
  101. int ContactNo;
  102. String SName;
  103. int Sem;
  104. int Marks;
  105.  
  106. public int getUsn() {
  107. return Usn;
  108. }
  109. public void setUsn(int usn) {
  110. Usn = usn;
  111. }
  112. public int getClg_code() {
  113. return Clg_code;
  114. }
  115. public void setClg_code(int clg_code) {
  116. Clg_code = clg_code;
  117. }
  118. public int getContactNo() {
  119. return ContactNo;
  120. }
  121. public void setContactNo(int contactNo) {
  122. ContactNo = contactNo;
  123. }
  124. public String getSName() {
  125. return SName;
  126. }
  127. public void setSName(String sName) {
  128. SName = sName;
  129. }
  130. public int getSem() {
  131. return Sem;
  132. }
  133. public void setSem(int sem) {
  134. Sem = sem;
  135. }
  136. public int getMarks() {
  137. return Marks;
  138. }
  139. public void setMarks(int marks) {
  140. Marks = marks;
  141. }
  142.  
  143. }
Add Comment
Please, Sign In to add comment