Friday, January 9, 2015

REST Web Service


-REST is alternative to SOAP and WSDL.

-Generally, the four primary HTTP verb are used as follows:

1.GET
Read a specific resource (by an identifier) or a collection of resources.
2.PUT
Update a specific resource (by an identifier) or a collection of resources.
Can also be used to create a specific resource if the resource identifier is know before-hand.
3.DELETE
Remove/delete a specific resource by an identifier.
4.POST
Create a new resource. Also a catch-all verb for operations that don't fit into the other categories.

- REST runs over HTTP (Hypertext Transfer Protocol)

-try this
  Facebook
           www.facebook.com/youtube
  https://graph.facebook.com/youtube
  https://graph.facebook.com/youtube?fields=id,name,likes

  GMAP
           https://maps.googleapis.com/maps/api/geocode/json?address=khamgaon&sensor=false
  Instagram
           http://instagram.com/developer
           click on-> API console
   

Thursday, January 8, 2015

Prepared Statement Java SQL Connection


import java.sql.*;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class demo123
{
public static void main(String[] args)
{
try
{

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

System.out.println("class found");
Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test","root","root");
System.out.println("class found1");
PreparedStatement ps = con.prepareStatement("select (password) from users where username= ? ");

ps.setString(1, "vishal");
ResultSet rs = ps.executeQuery();

if(rs.next())
{
String pass=rs.getString(1);
System.out.println("pss->"+pass);
}

} catch (Exception e)
{
System.out.println("Exception--->"+e);// TODO: handle exception
}

}

}


Wednesday, November 12, 2014

Extracting data from Mysql and creating PDF file using JAVA

//Table name : customer
// Database name: vishal
//PDF name : HelloWorld.pdf

package pdfread;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

public class CreatePDF
{
public static void main(String[] args) throws ClassNotFoundException, SQLException
{
Document document = new Document();
Connection conn = null;
Statement stmt = null;
try
{
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("/home/PdfLocation/HelloWorld.pdf"));
document.open();

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

// STEP 3: Open a connection
System.out.println("Connecting to database...");
conn = (Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/vishal", "root", "root");

PdfPTable table=new PdfPTable(6);

System.out.println("Creating statement...");
stmt = (Statement) conn.createStatement();
String sql= "SELECT * from customer";
ResultSet rs = stmt.executeQuery(sql);

while (rs.next()) {
table.addCell(rs.getString("TRNID"));
table.addCell(rs.getString("NAME"));
table.addCell(rs.getString("DATE"));
table.addCell(rs.getString("AMOUNT"));
table.addCell(rs.getString("MATCH_FLAG"));
table.addCell(rs.getString("PS"));
}

document.add(new Paragraph("Table customer.\n"));
document.add(table);
document.close();
writer.close();
} catch (DocumentException e)
{
e.printStackTrace();
} catch (FileNotFoundException e)
{
e.printStackTrace();
}
System.out.println("Done");
}
}

Tuesday, November 11, 2014

Using Hbase Hadoop (Steps)

Using Hbase

Hbase is upper layer to HDFS. It shows HDFS data in tablizer form.
After Hbase installation:
         check- localhost:50070
You will see data in table format.

Steps to start Hbase:

1: Format namenode
vishal@localhost:~/hadoop/bin$ ./hadoop namenode -format
2: Start Hadoop
        vishal@localhost:~/hadoop/sbin$ ./start-all.sh      
3: turn off safe mode
        vishal@localhost:~/hadoop/bin$ ./hadoop dfsadmin -safemode leave
4: Start Hbase
        vishal@localhost:~/Hbase/hbase-0.96.1.1-hadoop2/bin$ start-hbase.sh
5: Check java processes
@localhost:~/Hbase/hbase-0.96.1.1-hadoop2/bin$ jps
5523 DataNode
5965 NodeManager
6515 HQuorumPeer
6729 HRegionServer
6806 Jps
6578 HMaster
5837 ResourceManager
5700 SecondaryNameNode
5380 NameNode
6: Enter URL in Browser

        A) localhost:50070

    B) Click on Browse the filesystem



Batch Insert In MySQL using Java.



SQL Injection Safe Batch


import java.sql.Connection;
import java.sql.PreparedStatement;
String sql = "insert into student (name, city, phone) values (?, ?, ?)";
Connection connection = new getConnection();
PreparedStatement ps = connection.prepareStatement(sql);
for (Student stud: studentDB) {
    ps.setString(1, stud.getName());
    ps.setString(2, stud.getCity());
    ps.setString(3, stud.getPhone());
    ps.addBatch();
}
ps.executeBatch();
ps.close();
connection.close();        




Bulk data Insert in Mysql from txt file



Command:

- load data infile 'demo1.txt' into table demo fields terminated by ',' ;

   ...here demo is table name

Txt File- demo.txt

vishal,
ram,
rohit,
smita


Store file at var/lib/mysql/your_DB_Name/demo.txt
---------------------------------------------------



Tuesday, September 16, 2014

How To Change MySQL Root Password


You can change the mySQL root password using mysqladmin command as shown below. Please note that there is no space between -p and currentpassword.
# mysqladmin -u root -pcurrentpassword password 'newpassword'
Once you’ve changed it make sure you can login with your new password successfully as shown below.
# mysql -u root -pnewpassword
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.25-rc-community MySQL Community Server (GPL)
mysql>