Sunday, September 18, 2016

Number pattern horizontal pyramid

1
2*2
3*3*3
4*4*4*4
4*4*4*4
3*3*3
2*2
1
#include<stdio.h>
int main()
{
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
if(j<i)
printf("%d*",i);
else
printf("%d",i);
}
printf(" \n");
}
for(i=4;i>=1;i--)
{
for(j=1;j<=i;j++)
{
if(j<i)
printf("%d*",i);
else
printf("%d",i);
}
printf(" \n");
}
return 0;
}

Number pattern 1 22 333 4444 55555

1
22
333
4444
55555

#include <stdio.h>

int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}

return 0;
}

Number pattern 5 44 333 2222 11111

5
44
333
2222
11111

#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=5;j>=i;j--)
{
printf("%d",i);
}
printf("\n");
}

return 0;
}

Number pattern 55555 4444 333 22 1

55555
4444
333
22
1

#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}

return 0;
}

Number Pattern 11111 2222 333 44 5

11111
2222
333
44
5

#include <stdio.h>

int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
{
printf("%d",i);
}
printf("\n");
}

return 0;
}

Number Pattern 12345 4321 123 21 1

12345
4321
123
21
1

int main()
{
int i,j,k;
for(i=5;i>=1;i--)
{
if(i%2==1) k=1;
else k=i;
for(j=1;j<=i;j++)
{
printf("%d",k);
if(i%2==1) k++;
else k--;
}
printf("\n");
}
return 0;
}

Number Pattern 1234567 12345 123 1

1234567
12345
123
1

int main()
{
int i,j;
for(i=7;i>=1;i-=2)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}

Number Pattern 1 01 101 0101

1
01
101
0101

#include <stdio.h>
int main()
{
int i, j;
for(i=1;i<=4;i++)
{
for(j=i;j>=1;j--)
{
printf("%d",j%2);
}
printf("\n");
}
return 0;
}

Number Pattern 13579 3579 579 79 9

13579
3579
579
79
9

#include <stdio.h>
int main()
{
int i,j;
for(i=1;i<=9;i+=2)
{
for(j=i;j<=9;j+=2)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}

Number Pattern 1, 2 4,1 3 5, 2 4 6 8, 1 3 5 7 9

1
2 4
1 3 5
2 4 6 8
1 3 5 7 9

#include<stdio.h>
int main()
{
int i,j,k;
for(i=1;i<=5;i++)
{
if(i%2==0)
{
k=2;
}
else
{
k=1;
}
for(j=1;j<=i;j++,k+=2)
{
printf("%d ", k);
}
printf("\n");
}
return 0;
}

Number Pattern 55555 45555 34555 23455 12345

55555
45555
34555
23455
12345

int main()
{
int i, j, k;
for(i=5;i>=1;i--)
{
k = i;
for(j=1;j<=5;j++)
{
if(k <= 5)
{
printf("%d",k);
}
else
{
printf("5");
}
k++;
}
printf("\n");
}
return 0;
}

Number Pattern 12345 2345 345 45 5

12345
2345
345
45
5

code:

#include <stdio.h>

int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=i;j<=5;j++)
{
printf("%d",j);
}
printf("\n");
}

return 0;
}

Number Pattern 54321 4321 321 21 1

54321
4321
321
21
1

CODE:
#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=i;j>=1;j--)
{
printf("%d",j);
}
printf("\n");
}

return 0;
}

Number Pattern 54321 5432 543 54 5

54321
5432
543
54
5

CODE:

#include <stdio.h>

int main()
{
    int i, j;
    for(i=1;i<=5;i++)
    {
        for(j=5;j>=i;j--)
        {
            printf("%d",j);
        }
        printf("\n");
    }

    return 0;
}

Number Pattern 1 12 123 1234 12345

1
12
123
1234
12345

Code;

#include <stdio.h>

int main()
{
    int i, j;
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=i;j++)
        {
            printf("%d",j);
        }
        printf("\n");
    }

    return 0;
}

Number Pattern 5 45 345 2345 12345

5
45
345
2345
12345

CODE:
#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=i;j<=5;j++)
{
printf("%d",j);
}
printf("\n");
}

return 0;
}

Number Pattern 1 21 321 4321 54321

1
21
321
4321
54321

CODE:
#include <stdio.h>

int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=i;j>=1;j--)
{
printf("%d",j);
}
printf("\n");
}

return 0;
}

Number Pattern 5 54 543 5432 54321

5
54
543
5432
54321

CODE : 
#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=5;j>=i;j--)
{
printf("%d",j);
}
printf("\n");
}

return 0;
}

Number Pattern - 12345 1234 123 12 1

12345
1234
123
12
1

Code : 
#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}

return 0;
}

Saturday, September 17, 2016

File or image store into database by gwt

GreetingService.java


package com.client;


import com.google.gwt.user.client.rpc.RemoteService;


importcom.google.gwt.user.client.rpc.RemoteServiceRelativePath;


/**


 * The client side stub for the RPC service.


 */


@RemoteServiceRelativePath("greet")


public interface GreetingService extends RemoteService {


      String upload(String topic, String stream, String Tag, String plink, String fpath );


}


               


GreetinServiceAsync.java


package com.client;


import com.google.gwt.user.client.rpc.AsyncCallback;


/**


 * The async counterpart of <code>GreetingService</code>.


 */


public interface GreetingServiceAsync 
{


  void upload(String topic, String stream, String Tag, String plink, String fpath, AsyncCallback<String> callback );



}


TestExample.java


package com.client;


import com.google.gwt.core.client.EntryPoint;


import com.google.gwt.core.client.GWT;


import com.google.gwt.event.dom.client.ClickEvent;


import com.google.gwt.event.dom.client.ClickHandler;


import com.google.gwt.user.client.Window;


import com.google.gwt.user.client.rpc.AsyncCallback;


import com.google.gwt.user.client.ui.AbsolutePanel;


import com.google.gwt.user.client.ui.Button;


import com.google.gwt.user.client.ui.FileUpload;


import com.google.gwt.user.client.ui.Label;


import com.google.gwt.user.client.ui.ListBox;


import com.google.gwt.user.client.ui.RootPanel;


import com.google.gwt.user.client.ui.TextBox;


/**


 * Entry point classes define <code>onModuleLoad()</code>.


 */


public class TestExample implements EntryPoint


{


private final GreetingServiceAsync a1 = GWT.create(GreetingService.class);


        RootPanel rt;


        AbsolutePanel absolutePanel;


        TextBox textBox;


        ListBox comboBox;


        TextBox textBox_1;


        TextBox textBox_2;


        FileUpload fileUpload;


        Button button;


        String s1,s2,s3,s4,s5;


      public void onModuleLoad()


      {



              rt=RootPanel.get();



              absolutePanel = new AbsolutePanel();


              rt.add(absolutePanel, 218, 24);


              absolutePanel.setSize("445px", "434px");



              textBox = new TextBox();


              absolutePanel.add(textBox, 143, 39);



              Label lblTopic = new Label("Topic");


              absolutePanel.add(lblTopic, 86, 42);



              comboBox = new ListBox();


              comboBox.addItem("Computer Science");


              comboBox.addItem("Environment");


              comboBox.addItem("Physics");


              comboBox.addItem("Chemistry");


              comboBox.addItem("Biology");


              absolutePanel.add(comboBox, 143, 88);


              comboBox.setSize("148px", "24px");



              Label lblStreams = new Label("Streams");


              absolutePanel.add(lblStreams, 69, 88);



              textBox_1 = new TextBox();


              absolutePanel.add(textBox_1, 143, 139);



              Label lblTags = new Label("Tags");


              absolutePanel.add(lblTags, 87, 139);



              textBox_2 = new TextBox();


              absolutePanel.add(textBox_2, 143, 194);



              Label lblPublicLink = new Label("Public Link");


              absolutePanel.add(lblPublicLink, 49, 194);



              fileUpload = new FileUpload();


              absolutePanel.add(fileUpload, 143, 254);


              button = new Button("New button");


              absolutePanel.add(button, 156, 311);



              button.addClickHandler(new ClickHandler()


              {


                  public void onClick(ClickEvent event)


                  {


                        Window.alert("onclick");


                        String topic=textBox.getText();


                   String strm=comboBox.getItemText(comboBox.getSelectedIndex());


                        String tag=textBox_1.getText();


                        String plink=textBox_2.getText();


                        String fpath=fileUpload.getFilename();



        a1.upload(topic, strm, tag, plink, fpath, newAsyncCallback<String>() 
            {



              @Override


             public void onSuccess(String result)


             {


                 // TODO Auto-generated method stub


                  String f="yes";


                  System.out.println(result);


                  // TODO Auto-generated method stub


                  if(result.equals(f))


                  {


                     System.out.println("onsuccess");


                     Window.alert("File Upload");



                  }


                  else


                  {


                     Window.alert("Filis not uploaded");


                  }



           }



           @Override


           public void onFailure(Throwable caught) 
            {


                  // TODO Auto-generated method stub


                  Window.alert("Failure");


            }


        });


      }


   });


              button.setText("Uplod lctr notes");


              button.setSize("133px", "28px");



              Label lblFile = new Label("File");


              absolutePanel.add(lblFile, 98, 254);


              lblFile.setSize("27px", "21px");


    }


}


GreetingServiceimp.java


package com.server;


import java.io.File;


import java.io.FileInputStream;


import java.io.FileOutputStream;


import java.io.IOException;


import java.io.InputStream;


import java.sql.Connection;


import java.sql.DriverManager;


import java.sql.PreparedStatement;


import java.sql.ResultSet;


import java.sql.SQLException;


import java.sql.Statement;


import com.client.GreetingService;


importcom.google.gwt.user.server.rpc.RemoteServiceServlet;


/**


 * The server side implementation of the RPC service.


 */


@SuppressWarnings("serial")


public class GreetingServiceImpl extendsRemoteServiceServlet implements


    GreetingService


{



      Connection con=null;


      Statement st=null;


      ResultSet rs=null;


      String query;



      String url="jdbc:mysql://localhost:3306/gwtlogin";



 public void call()


 {


       try


       {


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


       }


       catch(ClassNotFoundException e)


       {


             System.out.print(e.getMessage());


       }


       try


       {


             con=DriverManager.getConnection(url, "root","");


             st=con.createStatement();


       }


       catch(SQLException e)


       {


             System.out.println(e.getMessage());


       }


 }


      @Override


public String upload(String topic, String stream, String Tag, String plink,


                  String fpath) {


            // TODO Auto-generated method stub


            call();


            String ss="no";


            int k=0;


          FileInputStream fis = null;


          PreparedStatement pstmt = null;



          System.out.println(fpath);


          try


          {


            System.out.println("Hello try");


            con.setAutoCommit(false);


            File file = new File(fpath);


            fis = new FileInputStream(file);


            pstmt = con.prepareStatement("insert into uploadfile(Topic, Stream, Tag, PublicLink, FileBody ) values ( ?, ?, ?, ?, ?)");


            //pstmt.setString(1, id);


            pstmt.setString(1, topic);


            pstmt.setString(2, stream);


            pstmt.setString(3, Tag);


            pstmt.setString(4, plink);


            pstmt.setAsciiStream(5, fis, (int) file.length());


            k=pstmt.executeUpdate();


            System.out.println("Bye");


            if(k==1)


                  {


                        ss="yes";



                  }


            con.commit();


          }


          catch (Exception e)


          {


            System.err.println("Error: " + e.getMessage());


            e.printStackTrace();


          }


          finally {


              try {


                        pstmt.close();


                  } catch (SQLException e) {


                        // TODO Auto-generated catch block


                        e.printStackTrace();


                  }


              try {


                        fis.close();


                  } catch (IOException e) {


                        // TODO Auto-generated catch block


                        e.printStackTrace();


                  }


              try {


                        con.close();


                  } catch (SQLException e) {


                        // TODO Auto-generated catch block


                        e.printStackTrace();


                  }


            }



          return ss;


      }


}


I hope you will able to store file into database. If any error has occurred or any question comes in your mind. Freely ask your problem by comment we just solve your problem within 1 hour.