Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create table workbrain.temp_entempol_end_dt_fix
- 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
- 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
- where e.ENTEMPPOL_END_DATE='01-jan-3000'
- and e.emp_id=p.emp_id;
- MERGE INTO ent_emp_policy e
- USING
- (
- SELECT * FROM workbrain.temp_entempol_end_dt_fix
- ) ef
- ON(e.ENTEMPPOL_ID=ef.ENTEMPPOL_ID)
- WHEN MATCHED THEN UPDATE SET
- e.ENTEMPPOL_END_DATE = ef.correct_end_dt;
- commit;
- `drop table workbrain.temp_entempol_end_dt_fix`;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import com.mysql.jdbc.PreparedStatement;
- public class PreparedStatementInsertingStatement
- {
- public static void main(String[] args) throws SQLException
- {
- Connection con=null;
- PreparedStatement ps=null;
- try
- {
- String name="Saurav";
- String class1="Btech";
- int rollno=2;
- Class.forName("com.mysql.jdbc.Driver");
- System.out.println("Drivers Loaded");
- con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/crawler","root","root");
- System.out.println("Connection Created");
- String sql="insert into crawler (name,class,rollno) values (?,?,?)";
- ps=(PreparedStatement)con.prepareStatement(sql);
- ps.setString(1,name);
- ps.setString(2, class1);
- ps.setInt(3, rollno);
- ps.executeUpdate();
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- package org.danish.java;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import com.mysql.jdbc.PreparedStatement;
- public class PreparedStatementSelectAll
- {
- public static void main(String[] args) throws SQLException
- {
- Connection con=null;
- PreparedStatement ps=null;
- ResultSet rs;
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- System.out.println("Drivers Loaded");
- con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/crawler","root","root");
- System.out.println("Connection Created");
- String sql="select * from crawler";
- ps=(PreparedStatement)con.prepareStatement(sql);
- rs=ps.executeQuery();
- while(rs.next())
- {
- int id=rs.getInt(1);
- String name=rs.getString(2);
- String class1=rs.getString(3);
- int rollno=rs.getInt(4);
- int salary=rs.getInt(5);
- System.out.println("Id="+id+" Name="+name+" Class="+class1+" Roll No= "+rollno+" Salary "+salary);
- }
- }
- catch (ClassNotFoundException e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- package org.danish.java;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import com.mysql.jdbc.PreparedStatement;
- public class PreparedStatementUpdate
- {
- public static void main(String[] args) throws SQLException
- {
- Connection con=null;
- PreparedStatement ps=null;
- try
- {
- String name="Saurav Soni";
- String class1="Btech";
- int rollno=2;
- int id=2;
- Class.forName("com.mysql.jdbc.Driver");
- System.out.println("Drivers Loaded");
- con=(Connection)DriverManager.getConnection("jdbc:mysql://localhost/crawler","root","root");
- System.out.println("Connection Created");
- String sql="update crawler set name=?, class=?, rollno=? where id=?";
- ps=(PreparedStatement) con.prepareStatement(sql);
- ps.setString(1, name);
- ps.setString(2, class1);
- ps.setInt(3, rollno);
- ps.setInt(4, id);
- long id1=ps.executeUpdate();
- System.out.println("Values Updated "+id1);
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement