Advertisement
Guest User

Untitled

a guest
Jan 12th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. create table workbrain.temp_entempol_end_dt_fix
  2. as select e.ENTEMPPOL_ID,e.emp_id,e.entemppol_start_date,e.ENTEMPPOL_END_DATE, nvl(lead (e.entemppol_start_date,1) over (partition by e.emp_id order by e.emp_id,e.entemppol_start_date)-1,e.ENTEMPPOL_END_DATE) as correct_end_dt
  3. from ent_emp_policy e ,(select e1.emp_id from ent_emp_policy e1 where e1.ENTEMPPOL_END_DATE='01-jan-3000' group by e1.emp_id having count(*)>1) P
  4. where e.ENTEMPPOL_END_DATE='01-jan-3000'
  5. and e.emp_id=p.emp_id;
  6.  
  7. MERGE INTO ent_emp_policy e
  8. USING
  9. (
  10. SELECT * FROM workbrain.temp_entempol_end_dt_fix
  11. ) ef
  12. ON(e.ENTEMPPOL_ID=ef.ENTEMPPOL_ID)
  13. WHEN MATCHED THEN UPDATE SET
  14. e.ENTEMPPOL_END_DATE = ef.correct_end_dt;
  15.  
  16.  
  17.  
  18.  
  19. commit;
  20.  
  21. `drop table workbrain.temp_entempol_end_dt_fix`;
  22.  
  23. import java.sql.Connection;
  24. import java.sql.DriverManager;
  25. import java.sql.SQLException;
  26.  
  27. import com.mysql.jdbc.PreparedStatement;
  28.  
  29. public class PreparedStatementInsertingStatement
  30. {
  31.  
  32.  
  33. public static void main(String[] args) throws SQLException
  34. {
  35. Connection con=null;
  36. PreparedStatement ps=null;
  37. try
  38. {
  39. String name="Saurav";
  40. String class1="Btech";
  41. int rollno=2;
  42. Class.forName("com.mysql.jdbc.Driver");
  43. System.out.println("Drivers Loaded");
  44. con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/crawler","root","root");
  45. System.out.println("Connection Created");
  46. String sql="insert into crawler (name,class,rollno) values (?,?,?)";
  47. ps=(PreparedStatement)con.prepareStatement(sql);
  48. ps.setString(1,name);
  49. ps.setString(2, class1);
  50. ps.setInt(3, rollno);
  51. ps.executeUpdate();
  52. } catch (ClassNotFoundException e) {
  53. // TODO Auto-generated catch block
  54. e.printStackTrace();
  55. }
  56. }
  57.  
  58. package org.danish.java;
  59.  
  60. import java.sql.Connection;
  61. import java.sql.DriverManager;
  62. import java.sql.ResultSet;
  63. import java.sql.SQLException;
  64.  
  65. import com.mysql.jdbc.PreparedStatement;
  66.  
  67. public class PreparedStatementSelectAll
  68. {
  69. public static void main(String[] args) throws SQLException
  70. {
  71. Connection con=null;
  72. PreparedStatement ps=null;
  73. ResultSet rs;
  74. try
  75. {
  76.  
  77. Class.forName("com.mysql.jdbc.Driver");
  78. System.out.println("Drivers Loaded");
  79. con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/crawler","root","root");
  80. System.out.println("Connection Created");
  81. String sql="select * from crawler";
  82. ps=(PreparedStatement)con.prepareStatement(sql);
  83. rs=ps.executeQuery();
  84. while(rs.next())
  85. {
  86. int id=rs.getInt(1);
  87. String name=rs.getString(2);
  88. String class1=rs.getString(3);
  89. int rollno=rs.getInt(4);
  90. int salary=rs.getInt(5);
  91. System.out.println("Id="+id+" Name="+name+" Class="+class1+" Roll No= "+rollno+" Salary "+salary);
  92. }
  93.  
  94. }
  95. catch (ClassNotFoundException e)
  96. {
  97. // TODO Auto-generated catch block
  98. e.printStackTrace();
  99. }
  100. }
  101.  
  102. }
  103.  
  104. package org.danish.java;
  105.  
  106. import java.sql.Connection;
  107. import java.sql.DriverManager;
  108. import java.sql.SQLException;
  109.  
  110. import com.mysql.jdbc.PreparedStatement;
  111.  
  112. public class PreparedStatementUpdate
  113. {
  114.  
  115.  
  116. public static void main(String[] args) throws SQLException
  117. {
  118. Connection con=null;
  119. PreparedStatement ps=null;
  120. try
  121. {
  122. String name="Saurav Soni";
  123. String class1="Btech";
  124. int rollno=2;
  125. int id=2;
  126. Class.forName("com.mysql.jdbc.Driver");
  127. System.out.println("Drivers Loaded");
  128. con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/crawler","root","root");
  129. System.out.println("Connection Created");
  130. String sql="update crawler set name=?, class=?, rollno=? where id=?";
  131. ps=(PreparedStatement) con.prepareStatement(sql);
  132. ps.setString(1, name);
  133. ps.setString(2, class1);
  134. ps.setInt(3, rollno);
  135. ps.setInt(4, id);
  136. long id1=ps.executeUpdate();
  137. System.out.println("Values Updated "+id1);
  138. } catch (ClassNotFoundException e) {
  139. // TODO Auto-generated catch block
  140. e.printStackTrace();
  141. }
  142. }
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement