java4all@1986 java. Powered by Blogger.
Showing posts with label JDBC. Show all posts
Showing posts with label JDBC. Show all posts

How to insert new records into database by checking that the record is already inserted or not?

>> Friday, June 17, 2011

import java.sql.*;
import java.util.Calendar;
import java.util.Date;
import java.util.StringTokenizer;
 

public class Test1 {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Connection conn = null;
       String url = "jdbc:mysql://192.168.1.101:3306/";//here 192.168.1.101 is server dsn Address(i.e in our system localhost)
       String dbName = "atrdev";
       String driver = "com.mysql.jdbc.Driver";
       String userName = "atrdev"; 
       String password = "centris";
       ResultSet  rs  =null; 
       PreparedStatement prest;
       Statement st;
      
       try{
       Class.forName(driver).newInstance();
       conn = DriverManager.getConnection(url+dbName,userName,password);
       Calendar now = Calendar.getInstance();
       
        String[] months = {"Jan", "February",    // 
         /* System.out.println("Current Year is : " + now.get(Calendar.YEAR));
          // month start from 0 to 11
          System.out.println("Current Month is : " + (now.get(Calendar.MONTH) + 1));
          System.out.println("Current Date is : " + now.get(Calendar.DATE));
     */
         "March", "April", "May", "June", "July",
         "August", "September", "October", "November",
         "December"};
        
         Calendar cal = Calendar.getInstance(); 
         String month = months[(cal.get(Calendar.MONTH)-1)];//to get previous month 
         System.out.println("month.................. "+month);
         boolean check=true;
        String query = "select  date_time from atr_employee_info_audit where  month_salary like'"+month+"%' order by date_time limit 1";//here LIMIT class is used to get record based on number here we had taken 1,if 2 means ,2 records
           st = conn.createStatement();
          
              rs= st.executeQuery(query);
                
                         
                             
           while(rs.next()){
            check=false;
               String s=rs.getString("date_time");
               System.out.println("false");
               String arr[]=s.split("-");
                   
                     System.out.println(arr[0]);
                     String ss=arr[0];//we get year 
                     System.out.println("dasddfa"+ss);
                    
                    Calendar cal1=Calendar.getInstance();
                    int year=cal1.get(Calendar.YEAR);
                    String yearstring = Integer.toString(year);
                    System.out.println("Current Year: "+yearstring );
            
                     
                     
             System.out.println("datetime"+s);
           }
           if(check==true)
           {
                                  //here if records are not avaiable w.r.t previous month then inserting records into dataBase
           st=conn.createStatement();
           int i=st.executeUpdate("insert into atrdev.atr_employee_info_audit  values (emp_info_audit_key, empcode, empname, emp_designation, emp_department, emp_bank_acc_no, emp_email, emp_no_ofdays_worked, emp_basic, emp_hra, emp_conveyance,emp_onsite_allowence,emp_medical,emp_pf_emp_con,emp_gross,emp_pf, emp_itax,emp_pro_tax,emp_other_deduct,emp_tot_deduct,emp_net_sal,date_time,month_salary,create_user,modify_user,message_body)");
            System.out.println(+i);
            System.out.println("ffdgfdgsdfgs");
           }
       }catch (Exception e) {
   // TODO: handle exception
        e.printStackTrace();
  }
 }

}

Read more...

What is meant By JDBC?

>> Monday, May 30, 2011

JDBC: The process of interacting with Data Base from Java Application.
  
 But as per JDBC application we will write Data Base Logic in Java Application,When we sent the Data Base logic to Data Base ,the Data Base Engine Could Not understand the Java provided DataBase logic,Why because Data Base Engine could understand only Query Language.In order to convert  the Java Language to Query Language and Query Language to Java Language we need an Interface Between between Java Application and Data Base.The interface which we are using in between Java Application and Data Base is called as "Driver".This Driver can be used to convert 
Java Language to Query Language and Query Language to Java Language.

Read more...

Which type of DataBase Management System we are using in our Application?

>> Sunday, May 29, 2011

We are using Relational Data Base Management System in our apllication
Relational Data Base Management System:  It is a Data Base Management System,which stores data in the form of Tables.This Data Base Management System understands only Query Language.

Read more...

What is meant by Query Processing?

Query Processing:   When we sent an sql Query from Sql Command Prompt to Data Base,then Database Engine we perform the following steps.

1.)Query Tokenization: In this phase it will take the provided Sql Query as input and divide into number of tokens,and generate stream of tokens as output.

2.)Query Parsing:T his phase will take stream of token as input and trying to construct a tree,If the tree is constructed successfully means there is no syntactical errors in provided SQL Query.

3.)Query Optimization:This phase will take the constructed tree as i/p and perform n.o optimization mechanisms in order to decrease the execution time and memory utilization.

4.)Query Execution:  This phase will take Query Optimization as i/p and execute by using n.o of interceptors internally.

Read more...

FaceBook Login

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

Total Pageviews

STATCOUNTER

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP