Monday 30 July 2012

How to get input in character type array in java

Hi ............
There are many way to get input in java. Java works on two type of stream 1. Character Stream 2. Byte Stream
Java treats Char data type different form c and c++. In C/C++ char data type hold 7 bit ASCII Character which is 0 to 127 characters but java char data type works on Unicode.
  • System.in.read() takes one character from user and return correspondence int value
  • for hold it we have to type cast in char
  • System.in.read() stop when user press enter its take it '\n'
class CharInput
{
           public static void main(String args[]) throws Exception
           {
                  char ar[]=new char[5];
                  int i;
                  for(i=0;i<ar.length;i++)
                  {
                          ar[i]=getChar();
                   }
            }
            static char getChar() throws Exception
            {
                   char ch=(char) System.in.read();
                   pressEnter();
                   return ch;
             }
             static void pressEnter() throws Exception
             {
                    while((char) System.in.read()!='\n');
              }
}  
  • As we know System.in.read() stop input when it encounter newline
  • i have make getChar function which is taking input from user and sure newline using pressEnter function
  • pressEnter is use to ensure newline character using while loop
  • loop stop when user press enter otherwise it looking in stream for new line

Wednesday 4 July 2012

Add Controls Run time in VB.NET & C#


hi............
Mostly we make control design time, we handle many event like click, mouseover,moueout etc. This is a easy process for design time because there is not any need to attach event handler visual studio attach necessary code automatically.
You can add control on run time………… for do this you will have to perform following steps
  • Make an object of relevant control
    eg. Button btn =new Button()      [C# ]
          dim btn as new Button()         [VB.NET]
  • After make an object of control you have to manage control property
    eg. Location,size,backcolor,text etc
  • You can also attach events..
Add an Button in C#
  Button btn = new Button();
            btn.Text="Click";
            btn.Location=new Point(100,100);
            btn.Click +=new EventHandler(btn_Click);
            this.Controls.Add(btn);
     following function will catch and handle button click event….
private void btn_Click(object sender,EventArgs e)
        {
            MessageBox.Show("Called");
        }
Add a combo box in vb.net
            Dim com As ComboBox
        com = New ComboBox
        com.Items.Add("one")
        com.Items.Add("two")
        com.Items.Add("three")
        com.Location = New Point(150, 100)
        AddHandler com.SelectedIndexChanged,AddressOf com_click
        Me.Controls.Add(com)
following function will catch and handle combo box
selectindexchange event….
       Private Sub com_click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        MsgBox("Called event")
    End Sub
       

Monday 2 July 2012

How to Retrieve records from ms access using date field in condition

Hi...... there
As you know SQL is a language which enable us to use database. If you've knowledge of SQL then you can operate any database software, for achieve this you just need to know how to run SQL Statement in that DBMS package
One thing you must know that there are some different in SQL in different DBMS package they use different data type and size, they treat date field as different way so if you want to use SQL you must know what are the SQL specification for that DBMS package
Develop Raj Kumar
Form of project
  • MS Access treat date field differently from SQL server
  • If you want to make a condition based on date you'll have to put date between ## e.g #7/28/2010
  • Import System.Data.OleDb name space for oledb class

     

     

     

    Save Button Code

    Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=your path")
            Try
                con.Open()
                Dim dd As String
                dd = DateTimePicker1.Value.Date
                Dim com As New OleDbCommand()
                com.Connection = con
                com.CommandText = "insert into stu values(" & TextBox1.Text & ",'" & TextBox2.Text & "','" & dd & "')"
                com.ExecuteNonQuery()
                MsgBox("Saved")
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try

    Search Button Code

     Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your Path")
            Dim da As New OleDbDataAdapter("select * from stu where dob=#" & DateTimePicker1.Value.Date & "#", con)
            Dim ds As New DataSet
            da.Fill(ds)
            DataGridView1.DataSource = ds.Tables(0)

Friday 8 June 2012

How to save a file from HTML File Control in AJAX Section Using ASP.Net with C#



    •     AJAX stands for Asynchronous  Java script and XML  
    •    AJAX enable a page asynchronously post back a page.  
    •   Only required part load from server instead of entire page so its   increase web performance.
    • Some control which are design for post back like file browser which can’t load a file if its not post back so you can’t upload a file when it’s in AJAX section.

        For upload a file in AJAX section using file browser you need to register a button for post back if user will click on than button then all page will be reloaded.
      <asp:UpdatePanel ID="U1" runat="server">
                <ContentTemplate>
      ....................................
      ....................................
               </ContentTemplate>
         <Triggers> 
             <asp:PostBackTrigger ControlID="saveButton">
         </Triggers>  
      </asp:UpdatePanel> 
      Here is your html code i leave ...... for your content Savebutton is a which post back entire page
      So i registered this button in trigger section post backTrigger register control which have to post back.....

Wednesday 6 June 2012

Create Album Using Java Script with fade effect



Hi.................
This post will help you to make a picture album.Pictures of album will change during a second internal.
I have done this with the help of java script.
  • This post will create a static album in nature you can't add a new image at run time if you want to add or remove image you will have to change java script code.
  • Save your picture in a folder and rename all picture into 1 to increasing order e.g (1.jpg , 2. jpg ,3,jpg...)
  • Count no. of picture in your folder because I'll use this number in java script code block
  • I used a timer which will run continue you can not stop it

Image Slide Show Using HTML

This is a presentation of a image slide show.This blog will help
you to make a moveable slide show right to left
This is a flat HTML coding.
This is achieve by marquee tag.Marquee tag has capacity to move any type of object inside it.I used marquee for make this slide show.


       

  • I saved my HTML file and all image in a folder so used relative path
  • if your image isn't in current folder then you need to provide full path of that image.....
   






Monday 4 June 2012

Save and Retrieve an image in Ms Access Using VB.Net

Hi.......
Its very simple to save and retrieve image in ms access for performing save retrieve you need to do something as mention...........
  • Aceess store image in binary format
  • We've to convert an image into binary at save time and binary ti bitmap at retrieve time

Database Table Structure 

 

 

 

 

 

 

 

 

 

  


Saturday 2 June 2012

Retrieve an Image from SQL Server in Picture Box Using VB.Net

Hi, There
Retrieving an image from sql server database is so simple just do following steps
  • Make a project and database which i mention in my Blog Take a look 
  • Add a picture box on your form, and a button for show image
  • On Show Button Click event paste following code

Friday 1 June 2012

Save an Image in SQL Server Database With VB.Net

Hi
Saving Image is an important part of any software,They're many ways to handling image.One easy and secure way is save your image in sql server database.If you want to save image in sql server then follow these steps
  • Make a database and a table with following description my database name is bsw and table name is stu
Database Table Structure

VB Project Controls Which you have to use
  •  You have to import 2 name space
    Imports System.IO
    Imports System.Data.SqlClient
  • Add OpenFileDialog control
  • And make a global string variable named str
    • On Browse picture button click paste following code
        OpenFileDialog1.ShowDialog()
         str = OpenFileDialog1.FileName
On Click event of save button paste following code


Dim con As New SqlConnection("initial catalog=bsw;data source=.;integrated security=true") Dim com As New SqlCommand()
Try
            Dim fs As New        FileStream(str,FileMode.Open)
            Dim data() As Byte = New [Byte](fs.Length) {}
            fs.Read(data, 0, fs.Length)
            fs.Close()
            'readed image
            Dim roll As New SqlParameter("roll", SqlDbType.Int)
            roll.Value = Val(TextBox1.Text)

            Dim name As New SqlParameter("name", SqlDbType.Char, 10)
            name.Value = TextBox2.Text

            Dim city As New SqlParameter("city", SqlDbType.Char, 10)
            city.Value = TextBox3.Text

            Dim img As New SqlParameter("img", SqlDbType.Image)
            img.Value = data
            'Adding parameters
            com.Parameters.Add(roll)
            com.Parameters.Add(name)
            com.Parameters.Add(city)
            com.Parameters.Add(img)
            con.Open()
            com.Connection = con
            com.CommandText = "insert into stu values(@roll,@name,@city,@img)"
            com.ExecuteNonQuery()
            MsgBox("Saved")
            Me.StuTableAdapter.Fill(Me.BswDataSet1.stu)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

Tuesday 21 February 2012

Complete menu based java database program for read,write,delete,update


hi folks
this is complete menu based program  java database read write.You'll have to set odbc driver which i have mention in java database connection blog
paste following code in your editor compile and run.....

import java.sql.*;
import java.io.*;
class dataoperation
{
        String nm,ct,db,cls;
        int rl;
        Connection con=null;      
        DataInputStream da=new DataInputStream(System.in);
        Statement stmt=null;
        dataoperation()
        {
                cls="sun.jdbc.odbc.JdbcOdbcDriver";
                db="jdbc:odbc:mydata";
                try
                {
                        Class.forName(cls);
                        con=DriverManager.getConnection(db,"","");
                        stmt=con.createStatement();
                }
                catch(Exception ex)
                {
                        System.out.println("Error : "+ex.getMessage());
                }
               
        }
        void write()
        {
                try
                {
                     
                        System.out.print("Enter Roll ");
                        rl=Integer.parseInt(da.readLine());
                        System.out.print("Enter name  ");
                        nm=da.readLine();
                        System.out.print("Enter city ");
                        ct=da.readLine();
                      
                        stmt.executeUpdate("insert into stu values("+rl+",'"+nm+"','"+ct+"')");
                        System.out.println("\nInserted");
                      
                }
                catch(Exception ex)
                {
                    System.out.println("Error : "+ex.getMessage());
                }
               
        }
        void delete()
        {
            System.out.println("Enter Roll ");
           
            try
            {
                rl=Integer.parseInt(da.readLine());
                stmt.executeUpdate("delete from stu where roll="+rl);
            }
            catch(Exception ex)
            {
                System.out.println("Error : "+ex.getMessage());
            }
        }
        void update()
        {
            try
            {
                System.out.print("Enter roll ");
                rl=Integer.parseInt(da.readLine());
                System.out.print("Enter Name ");
                nm=da.readLine();
                System.out.print("Enter City ");
                ct=da.readLine();
                stmt.executeUpdate("update stu set name='"+nm+"', city='"+ct+"' where roll="+rl);
               // con.close();
                System.out.print("\nRecord Updated");
            }
            catch(Exception ex)
            {
                System.out.print("\nError"+ex.getMessage());
            }
        }
        void print()
        {
            System.out.println("\n\n********* OUTPUT *************");
            try
            {
                ResultSet rlt=stmt.executeQuery("select * from stu");
                while(rlt.next())
                {
                    System.out.print("\t"+rlt.getString(1)+" "+rlt.getString(2)+" "+rlt.getString(3)+"\n");
                }
            }
            catch(Exception ex)
            {
                System.out.print("\nError : "+ex.getMessage());
            }
            System.out.println("\n****************************\n\n");
        }
}


class dbcomplete
{
   
   
    public static void main(String[] args) throws Exception
    {
       int opt;
       DataInputStream da=new DataInputStream(System.in);
       dataoperation ob=new dataoperation();
       do
       {
           System.out.println("****************************************");
           System.out.print("\n1. Add\n2. Delete\n3. Update\n4. Print\n0. Exit\n****************************************");
           System.out.print("\nEnter Your choice ");
           opt=Integer.parseInt(da.readLine());
           switch(opt)
           {
               case 1:
                    ob.write();
                    break;
               case 2:
                   ob.delete();
                   break;
               case 3:
                   ob.update();
                   break;
               case 4:
                   ob.print();
                   break;
               case 0:
                   break;
               default:
                   System.out.print("\nInvalid choice");
           }
          
       }while(opt!=0);
    }
   
}

Thursday 16 February 2012

How to delete record from Ms Access in Java








rajkumar9795@gmail.com
for delete a record in access follow instruction as mention in file connection blog 

Monday 13 February 2012

Connect Ms Access 2003 with Java (jdk1.3)


Hi
friends and student
 i was thinking from a long time how can i connect jdk1.3 to database.
Its very exciting and easy... Plz do following steps
1. Make a database in Ms Access
2. My Database name is bsw and table named stu(name,city)
3. Open Control panel>Administor>Data Sources(ODBC)
4.Select Ms Access (*.mdb) > Add
5. Write appropriate name of your ODBC Name
6. Select Database from select button
7. Paste this code,compile run and enjoy your database Connectivity


import java.sql.*;
import java.io.*;
class con2test
{
             public static void main(String[] args)
             {
                         // change this to whatever your DSN is
                         String dataSourceName = "mdbTEST";  //mdbTest is name which u hv mention in odbc data source name window
                         String dbURL = "jdbc:odbc:" + dataSourceName;
                         try
                        {
                                    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                                    Connection con = DriverManager.getConnection(dbURL, "","");    

                                     
                                    String nm;
                                    DataInputStream da=new DataInputStream(System.in);
                                    System.out.print("Enter name ");
                                    nm=da.readLine();
                                    System.out.print("Enter address ");
                                    address=da.readLine();
                                    Statement s = con.createStatement();
                                    s.executeUpdate("insert into user

values('"+nm+"','"+address+"')");
                                    con.close();
                                    System.out.println("Saved");
                                 
                         }
                         catch (Exception err)
                        {
                                    System.out.println( "Error: " + err );
                         }
             }
}