Friday, July 27, 2012

How To Establish Java MySql Connection

Connect your java program to MySQL database in 5 simple steps

Accessing a database is one of the basic and essential function that a java program has to perform. So let me help you to connect your java program to a MySQL Database.


Follow these procedures carefully to establish MySQL database connectivity in your java program.


STEP 1
:Download and install MySQL. If you don't have  MySQL installed on your system then download it. 
                                                You can download MySQL from here.


STEP 2: Configure MySQL using "Server Instance Configuration Wizard" (It automatically runs after installation,if not you can start it from MySQL installation folder). It will prompt you to set a password for the database.This password will be required to access the database.


STEP 3: Download JConnector From here. Jconnector is a .jar file which makes the Java-MySQL connection Possible.

STEP 4: Copy the downloaded "mysql-connector-java-5.0.8-bin.jar"(version number may vary)  file from the downloaded package to the location specified below.
          
             Java Installation Folder->jre->lib->ext
        
            Example:  E:\Java7\jdk1.6.0_21\jre\lib\ext

STEP 5: Now is the coding part.We have to include java codes for accessing the database in the program. We have to import java.sql package to the program for that purpose A sample code for establishing Connection is given below.(The code is partial and ephasise only database access)



import java.sql.*;

try
{


/*For Loading Driver*/

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

/*For creating a connection with Mysql database*/

Connection c=DriverManager.getConnection("jdbc:mysql://localhost:3306/Database_name","root","password");



/*For creating a Statement*/

Statement d=c.createStatement();


/*For retrieving result and for executing query*/

ResultSet rst=d.executeQuery("select item from login");
while(rst.next())
{
item=rst.getInt(1);
}



/*closing the statement*/

d.close();


/*closing the connection*/

c.close();


/*For catching and  displaying exceptions if any*/
}catch(Exception e)
{
System.out.println(e.getMessage());
}


You can learn more about JDBC and java sql codes in Oracle Tutorials.

Thursday, July 26, 2012

Earn Money Blogging

A Blog is much similar to a mini-website.The name blog evolved from the word 'web log'. Before you enter the world of blogs, it will be better that you read my article about content writing.


Selecting a Niche For Your Blog

This is the most important step which can be a deciding factor of your success as blogger.You should select a topic as per your area of interest, not based on the commercial interests. It is important that the topic should be of your interest, if you want to provide good quality content for your readers.To know more about topic selection and tips, read my article  Earn Money Online Through Content Writing.


Registering a Domain

You will need a top level domain in order to get fast approval of the ad programs and affiliate programs. Ads and affiliate programs are major income sources of a blog.Top level domains gives higher search engine visibility and ranking. You can make use of a free domain registrar like co.cc or .tk. But now a days search engines are demoting these free domains so you better register a commercial domain like .com or .co or any other related to your region.
                                           
                                     REGISTER A FREE TOP LEVEL DOMAIN HERE
OR

Custom domains are very much required to retain your readers and subscribers when you change your host or platform. My advice is go for a commercial domain. It will only cost you about $7 a year.


Find a Host For Your Blog

The next step is to find a host for your blog who allows advertising.For that you can depend blogger. Blogger is free blog hosting service of google. Blogger allows its users to create blogs and publish it on custom domains. That is you can use the custom domain registered in above step with a blog in blogger. Blogger is one of the worlds popular blogging platforms. It is very easy to start blogging with Blogger.You don't need any knowledge in html or other technical expertise to use blogger.
                                           


OR 

You can use other platforms like wordpress. But if you don't wanna pay for hosting then blogger will be the best choice. 
If you are ready to purchase hosting then I would recommend setting up your blog with a free host first and then moving towards a paid host or upgrade your account to paid hosting account. Because it will take some time to put up hosts. A free account will be sufficient to handle your traffic at the initial stage of your blog. You can get free hosting in the link below.





Preparing Your Blog

 

  •  Setting up the blog to use custom domain
While creation of your blog you will be given a blogspot subdomain like yourblog.blogspot.com if you are using blogger.Now you have to configure your blogger blog to use the custom domain. This procedure is explained in this video.
  • Posting on your blog
Write posts as frequent as possible.Try to write at least one post per week because posting frequency is a very important factor in generating traffic and in keeping your current readers satisfied.
  • Designing your blog
Design your blog template is also important. Select a template which is attractive and is suitable for your niche. Enable Feed subscription and Email feed subscription by signing up on feedburner. Twitter is also a good tool for keeping your regular readers updated about new posts.


 Monetization Of Your Blog

In-order to earn money from blogging you have to convert your visitors into money. For that you have to do any of the following.
  • Sign up for an Ad Publisher Program
You have to sign up for one of the ad publisher programs as a primary means of earning money from your blog. Adsense is the best one around.Blogger Provides in built support for Adsense.But dont expect to get approved by Adsense easily. Your blog must be atleast 6 months old and should have good traffic inorder to get adsense approval.So it will be wise to apply for an adsense account only after 6 months.
You can sign up for publishers like Infolinks, Bidvertiser etc as an alternative option.
  • Sign up for affiliate programs
You can sign up for affiliate programs like amazon affiliates if you plan to sell  or promote their goods like books DVDs etc. They will pay you commission for each sales through your blog.A whole lot of affiliate programs are there in the web. Just google them out.


Driving Traffic To Your Blog

Traffic is the factor that decides how much you earn from your blog. Earnings of your blog is directly linked to the traffic. So in-order to Earn money from Blogging you must ensure good traffic to your blog.For that
  • Advertise your blog well among your family and friends.
  • Use social networking tools such as Twitter and Facebook for exposing your blog.
  • Read other blogs with same niche and make relevant comments on them. This will increase your traffic considerably.
  • You can make use of google adwords to purchase traffic to your site if you have money to spend on it.



GOOD LUCK !!
 source:- Originally taken from my knol article (google knol)