Showing posts with label Java Tutorial. Show all posts
Showing posts with label Java Tutorial. Show all posts

Monday, 16 September 2013

Separation of Number And Char from String.

Separation of Number And Char from String.

Program:


public class DemoProgram {
public static void main(String[] args) {
String s = "(123)-456SS-7891ABCC";
String s1 = "(123)-456SS-7891ABCC";
   s = s.replaceAll("[^0-9]", "");
   s1 = s1.replaceAll("[^a-z|A-Z]", "");
   System.out.println("Number=="+s);
   System.out.println("Char=="+s1);

}

OutPut:
Number==1234567891
Char==SSABCC

Thursday, 22 August 2013

Sorting Array (Bubble Sort)

public class Sorting {


public static void main(String[] args) {

int a[]={9,3,6,8,1,2,4,6};
for(int i=0;i<a.length;i++)
{
System.out.print(a[i]);
}
System.out.println("\n");
int temp;
for(int k=0;k<a.length;k++)
{
 for(int z=0;z<a.length-1;z++)
 {
if(a[z] > a[z+1])
{
temp=a[z];
a[z]=a[z+1];
a[z+1]=temp;
}

 }
}
for(int i=0;i<a.length;i++)
{
System.out.print(a[i]);
}
}

}


Out Put

93681246

12346689

Wednesday, 19 June 2013

Call The Stored Procedure Using Java Program

Step 1:

Create a Stored Procedure in MySQL.

For Eg.

 BEGIN
SELECT order_No,Person_Name,Posting_Date,PlantID,Material,Activity,WorkCenter,Yield_Entity,Yield_Unit,Confirmation FROM production_confirmation where (order_No like ordernumber) AND (PlantID like plant) AND (Person_Name like name) AND (Posting_Date like pdate) ;
END

Parameters:

ordernumber varchar(20),plant varchar(20),name varchar(20),pdate varchar(15)


Step 2;

Write a Java Program to Connection to MySQL


Class.forName("com.mysql.jdbc.Driver");

Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/project", "root",  "root");

Statement st=con.createStatement();

st.execute("call Store_Procedure('"+value1+"','"+value2+"','"+value3+"','"+value4+")");

ResultSet rs=(ResultSet) st.getResultSet();

rs.next();

String =rs.getString("order_No");

 

Done ................










Thursday, 16 May 2013

File Handling Using Java

Create Class File.Java
import FILE IO.*;

Example Code for Creating Folder



 // Report is the name of Folder Witch You want to create
    File path = new File("E:\\Report");
   System.out.println("path=="+path);

// Check Folder Is available Or Not  in given Directory

                     File file2 = new File("E:\\Report");
                    if (!file2.exists()) {
                    file2.mkdir();
                    }
//If Exist then Create Directory in file name and copy File into directory


if (file2.exists())
{
      File file1 = new File("E:\\Report\\"+filename+"\\"+filename);
                if (file1.mkdir()) {
                System.out.println("File Name Directory is created!");
                File uploadedFile = new File(file1 + "/" + filename);
                item.write(uploadedFile);
               
                } else {
                System.out.println("Failed to create directory!");
                }
      }





Delete Empty Directory
use This Code
File directory = new File("E:\\Report\\"+filename);
directory.delete();

//If the directory contain File then use this code


File fin = new File("E:\\Filename");
   System.out.println("fin-"+fin);

   for (File file : fin.listFiles()) {
       try {
FileDeleteStrategy.FORCE.delete(file);
System.out.println("delete");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
      // Delete when directory is empty
              fin.delete();
   }





Tuesday, 16 April 2013

Create Jasper Report


Step 1:
Create .jrxml file using Ireport Tool
File->new->file name
Step 2:
Get Table in control  and drag into details band and follow instructions.
















































































































Final Result:
Show in jasper viewer.


















Another way to call .jrxml file into java

Add jar



























 Create Java class and Refer the code

String qu="SELECT * from role";
Statement statement = (Statement) connection.createStatement();
ResultSet resultSet = (ResultSet) statement.executeQuery(qu);
jasperDesign = JRXmlLoader.load("F://project backup//Report5.jrxml");
jasperReport = JasperCompileManager.compileReport(jasperDesign);
jasperPrint = JasperFillManager.fillReport(jasperReport,parameters, new JRResultSetDataSource(resultSet));
JasperViewer.viewReport(jasperPrint, false);


Use resultset to show the result in Jasper viewer.