Tuesday, December 8, 2015

File Move

// Import for File class
import java.io.*;

class Yes
{

 public static void main(String args[]) throws IOException
 {

 // Create a file object for directory C:\java
 File f=new File("D:\\Root\\Test\\");

 String s=f.getAbsoluteFile().getParentFile().getName();

 System.out.println(s);

 // List all the files in the directory, get their File objects.
 File[] files=f.listFiles();

  // Loop till end of all files
  for(int i=0;i<files.length;i++)
  {

  // Get the name of each file
  String name=files[i].getName();

  // File should not be a directory, and file should have an extension [this logic also filters folders containing .]
  if(!files[i].isDirectory())
  {

   if(name.contains(".dat")||name.contains(".prm"))
   {

   // Print the name of the file, and the extension
   System.out.println(name);
  
   FileReader in = new FileReader(f+"\\"+name);
   FileWriter out = new FileWriter("D:\\Root\\Test2\\"+name);
  
  
   int c;

   while ((c = in.read()) != -1)
     out.write(c);
  

   in.close();
   out.close();
  
  
 }
  
 }
 
  }
  System.out.println("Moving Done");
 }

}

Tuesday, August 25, 2015

// Include ( Copy ) the Driver file to the Project file.


File sourceFile = new File("velocity-1.5.jar");
String name = sourceFile.getName();

File targetFile = new File(path2+"\\"+name);
System.out.println("Copying file : " + sourceFile.getName() +" from Java Program");

//copy file from one location to other
try {
FileUtils.copyFile(sourceFile, targetFile);
System.out.println("Included the Driver to the Project");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

Friday, August 14, 2015

SP Inputs



cStmt.registerOutParameter("inOutParam", Types.INTEGER);
cStmt.setInt(2, 1);
int outputValue = cStmt.getInt(2);
----
getBigDecimal(int, int)
Get the value of a NUMERIC parameter as a java.math.BigDecimal object.
 o  getBoolean(int)
Get the value of a BIT parameter as a Java boolean.
 o  getByte(int)
Get the value of a TINYINT parameter as a Java byte.
 o  getBytes(int)
Get the value of a SQL BINARY or VARBINARY parameter as a Java byte[]
 o  getDate(int)
Get the value of a SQL DATE parameter as a java.sql.Date object
 o  getDouble(int)
Get the value of a DOUBLE parameter as a Java double.
 o  getFloat(int)
Get the value of a FLOAT parameter as a Java float.
 o  getInt(int)
Get the value of an INTEGER parameter as a Java int.
 o  getLong(int)
Get the value of a BIGINT parameter as a Java long.
 o  getObject(int)
Get the value of a parameter as a Java object.
 o  getShort(int)
Get the value of a SMALLINT parameter as a Java short.
 o  getString(int)
Get the value of a CHAR, VARCHAR, or LONGVARCHAR parameter as a Java String.
 o  getTime(int)
Get the value of a SQL TIME parameter as a java.sql.Time object.
 o  getTimestamp(int)
Get the value of a SQL TIMESTAMP parameter as a java.sql.Timestamp object.
 o  registerOutParameter(int, int)
Before executing a stored procedure call, you must explicitly call registerOutParameter to register the java.sql.Type of each out parameter.
 o  registerOutParameter(int, int, int)
Use this version of registerOutParameter for registering Numeric or Decimal out parameters.
 o  wasNull()
callableStatement.setInt(1, 10);
callableStatement.registerOutParameter(2, java.sql.Types.VARCHAR);
callableStatement.registerOutParameter(3, java.sql.Types.VARCHAR);
callableStatement.registerOutParameter(4, java.sql.Types.DATE);
String userName = callableStatement.getString(2);
String createdBy = callableStatement.getString(3);
Date createdDate = callableStatement.getDate(4);

call.registerOutParameter(1, Types.INTEGER);

BIGINT  long[]    long
BINARY byte[][]                byte[]
BIT          boolean[]            boolean
DATE     java.sql.Date[]  java.sql.Date
DOUBLE               double[]              double
FLOAT   double[]              double
INTEGER              int[]       int
LONGVARBINARY            byte[][]                byte[]
REAL      float[]   float
SMALLINT           short[]  short
TIME      java.sql.Time[]  java.sql.Time
TIMESTAMP       java.sql.Timestamp[]     java.sql.Timestamp
VARBINARY


  • getBoolean()
  • getByte()
  • getBytes()
  • getDate()
  • getDouble()
  • getFloat()
  • getInt()
  • getLong()
  • getObject()
  • getShort()
  • getString()
  • getTime()
  • getTimestamp()
  • registerOutParamter()


Sunday, August 2, 2015

DB_Test:

package gui_Design;

import java.sql.*;

public class DB_Connection_Test extends GUI_Design{


String DB_URL=Text1;
String UserName=Text2;
String Password=Text3;
String[] Driver_Class = 

{
"com.ibm.db2.jdbc.app.DB2Driver",
"com.mysql.jdbc.Driver",
"oracle.jdbc.driver.OracleDriver",
"com.microsoft.sqlserver.jdbc.SQLServerDriver",
"org.postgresql.Driver"

};




public void DB_Connection()
{

try {
            Class.forName(Driver_Class[0]);
        }
        
catch (ClassNotFoundException e)

{
            System.out.println("Please include Classpath  Where DB Driver is located");
            
            
        }
       
System.out.println("Driver is loaded successfully");
       
Connection conn = null;

       
        try {
            conn = DriverManager.getConnection(DB_URL,UserName,Password);
           
            if (conn != null)
            {
                System.out.println("Database Connected");
            }
            else
            {
                System.out.println("Database Connection Failed ");
            }
       
        
        } catch (SQLException e) {
           
       
        System.out.println("Database connection Failed");
        }

}



public void SQL_Query_Test()
{

}

public void SP_Test()
{

}

}


Buffer Test: 

import java.awt.Color;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

import javax.swing.DefaultCellEditor;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;

public class TablesDesign {
 
static String p,q;
static Boolean caught;
static String sb3;
static StringBuffer SB3=null;
static void Frame()
 {
  final JFrame Frame = new JFrame("SP- Inputs & Outputs");
  Frame.setBounds(300, 200, 500, 270);
   Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
  final JPanel LPanel = new JPanel();
  final JPanel RPanel = new JPanel();
  LPanel.setLayout(null);
  RPanel.setLayout(null);
  
  LPanel.setBackground(Color.black);
  LPanel.setBounds(0, 0, 290, 200);
  RPanel.setBounds(300, 0, 180, 200);
  RPanel.setBackground(Color.red);
  
  final JPanel LPanel1 = new JPanel();
  final JPanel RPanel1 = new JPanel();
  LPanel1.setLayout(null);
  RPanel1.setLayout(null);
  
  LPanel1.setBackground(Color.black);
  LPanel1.setBounds(0, 0, 290, 200);
  RPanel1.setBounds(300, 0, 180, 200);
  RPanel1.setBackground(Color.red);
  
  
  
  String columnNames[] = { "INPUT DATA TYPE", "VALUE"};
      String columnNames2[] = {"OUTPUT RETURN TYPE"};
     Object[][] data = new Object[2][2];
     Object[][] data2 = new Object[4][2];
     DefaultTableModel tableModel = new DefaultTableModel(data,columnNames);
     final JTable table = new JTable(data,columnNames);
     final JTable table1 = new JTable(data2,columnNames2);
     
     
     JScrollPane scroll1 = new JScrollPane(table);
     scroll1.setBounds(0, 0, 290, 200);
     scroll1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
     LPanel.add(scroll1);
     
     JScrollPane scroll2 = new JScrollPane(table1);
     scroll2.setBounds(0, 0, 180, 200);
     scroll2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
     RPanel.add(scroll2);
     
     table.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(
          new JComboBox(new DefaultComboBoxModel(new String[] {
             "int",
                 "String",
                 "float",
                 "Char",
                 "xml",
                 "json"
               }))));
    
   
     table1.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(
          new JComboBox(new DefaultComboBoxModel(new String[] {
                 "int",
                 "String",
                 "float",
                 "Char",
                 "Date",
                 "Varchar"
               }))));
     
     
     final JButton Button1 = new JButton("OK" );
     
     
     Button1.setBounds(200, 210, 60, 25);
     Frame.add(Button1);     
     
     Button1.addActionListener(new ActionListener() {
    
     
     
    @Override
        public void actionPerformed(ActionEvent e) {
     caught = false;
   
     StringBuilder buf = new StringBuilder();
     try
    {
    for (int t=0;t<=1;t++)
        {
         
             
        table.getCellEditor(t,1).stopCellEditing();
        table1.getCellEditor(t,0).stopCellEditing();
         
             p =  (String) table.getModel().getValueAt(t, 0);
            q = (String) table.getModel().getValueAt(t, 1);

            for (int t1=0;t1<=3;t1++)
                {
                       
                table1.getCellEditor(t1,0).stopCellEditing();
                 
                     p =  (String) table1.getModel().getValueAt(t1, 0);
                     
                   sb3="Output_"+t1+"+"+"\"\\"+"n"+"\"+";

                     buf.append(sb3);
                  System.out.println();
                 
                   
        }
            caught =true;
             
             
        }
    String result = buf.toString();
    String Output_B="\"Output Return Values: \"+";
    String Output_E="\"\\"+"\\End"+"\"";
    StringBuilder Output_F=new StringBuilder();
    Output_F.append(Output_B).append(result).append(Output_E);
    System.out.println(Output_F);
    }
    catch (Exception Test)
    {
    JOptionPane.showMessageDialog(null,"Input type/Output type should not be empty"+Test);
    caught = false;
     
     
    } finally {
               if(caught == false){
                  
                System.out.println("Not Done");
               }
               else
               {
                JOptionPane.showMessageDialog(null,"Done");
               }
    }
    }
     
     }
     
    );
     
     
    
     
     
     JButton Button2 = new JButton("Cancel" );
     
 Button2.addActionListener(new ActionListener() {
    
     
     
    @Override
        public void actionPerformed(ActionEvent e) {
     
    if ( caught == false)
    {
    System.out.println("Variables are not created successfully");
   
    }
    else 
    {
    System.out.println("Variables are created Successfull....");
   
    // Scanner sc = new Scanner(ClassLoader.class.getResourceAsStream("Drivers\\Test.jar"));
     
    String nn= ClassLoader.class.getName();
    System.out.println(nn);
  }
    }
    });
     
     
     Button2.setBounds(270, 210, 80, 25);
     Frame.add(Button1);
     Frame.add(Button2);
  Frame.add(LPanel);
  Frame.add(RPanel);
  
  Frame.setLayout(null);
  
  Frame.setVisible(true);
 }
 
 public static void main(String[] args) {
  
  Frame();
  
 }
}

Thursday, July 30, 2015

package gui_Design;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.StringWriter;

import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;

public class FinalTest {
static StringBuffer stringBuffer = new StringBuffer();
public static void main(String[] args) throws Throwable {
Uma();
}

static void Uma() throws Throwable
{
try {
File file = new File("C:/Users/Mahesh/Desktop/Ma.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);

String line;
while ((line = bufferedReader.readLine()) != null) {
// if (Integer.parseInt(line)<1)
//
// {
// stringBuffer.append(line+"\"+");
// stringBuffer.append("\n");
// }
//
stringBuffer.append("\""+line+"\"+");
stringBuffer.append("\n");

}
fileReader.close();
//System.out.println("Contents of file:");
System.out.println(stringBuffer.toString());



} catch (IOException e) {
e.printStackTrace();
}
VelocityEngine ve = new VelocityEngine();

        ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
        ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
       
 
   ve.init();
   org.apache.velocity.Template t = ve.getTemplate( "gui_Design/SP_Template.vm" );
   VelocityContext context = new VelocityContext();
 
   context.put("output", stringBuffer.toString());
        StringWriter writer = new StringWriter();
       
   t.merge(context,writer);
   System.out.println(writer);
 

}


}