// Create statement object Statement stmt = conn.createStatement(); // Set auto-commit to false conn.setAutoCommit(false); // Create SQL statement String SQL = "INSERT INTO Employees (id, first, last, age) " + "VALUES(200,'Zia', 'Ali', 30)"; // Add above SQL statement in the batch. stmt.addBatch(SQL); // Create one more SQL statement String SQL = "INSERT INTO Employees (id, first, last, age) " + "VALUES(201,'Raj', 'Kumar', 35)"; // Add above SQL statement in the batch. stmt.addBatch(SQL); // Create one more SQL statement String SQL = "UPDATE Employees SET age = 35 " + "WHERE id = 100"; // Add above SQL statement in the batch. stmt.addBatch(SQL); // Create an int[] to hold returned values int[] count = stmt.executeBatch(); //Explicitly commit statements to apply changes conn.commit();
Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts
Saturday, September 13, 2014
Bulk Crud Operation no database using java batch() execution
Wednesday, September 3, 2014
JAVA DBE READER
STEP 1: Download jar file & add in ur project
DOwnload link :http://www.java2s.com/Code/Jar/c/Downloadcomlinuxense10jar.htm
Step 2:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package jdbf;
/**
*
* @author saurabh-it
*/
import java.io.*;
import com.linuxense.javadbf.*;
public class JavaDBFReaderTest {
public static void main( String args[]) {
try {
// create a DBFReader object
//
InputStream inputStream = new FileInputStream("PATH_OF _UR_.DBF_FILE"); // take dbf file as program argument
DBFReader reader = new DBFReader( inputStream);
// get the field count if you want for some reasons like the following
//
int numberOfFields = reader.getFieldCount();
// use this count to fetch all field information
// if required
//
for( int i=0; i<numberOfFields; i++) {
DBFField field = reader.getField( i);
// do something with it if you want
// refer the JavaDoc API reference for more details
//
System.out.println( field.getName());
}
// Now, lets us start reading the rows
//
Object []rowObjects;
while( (rowObjects = reader.nextRecord()) != null) {
for( int i=0; i<rowObjects.length; i++) {
System.out.println( rowObjects[i]);
}
}
// By now, we have itereated through all of the rows
inputStream.close();
}
catch( DBFException e) {
System.out.println( e.getMessage());
}
catch( IOException e) {
System.out.println( e.getMessage());
}
}
}
STEP 2: RUN IT ... :)
DOwnload link :http://www.java2s.com/Code/Jar/c/Downloadcomlinuxense10jar.htm
Step 2:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package jdbf;
/**
*
* @author saurabh-it
*/
import java.io.*;
import com.linuxense.javadbf.*;
public class JavaDBFReaderTest {
public static void main( String args[]) {
try {
// create a DBFReader object
//
InputStream inputStream = new FileInputStream("PATH_OF _UR_.DBF_FILE"); // take dbf file as program argument
DBFReader reader = new DBFReader( inputStream);
// get the field count if you want for some reasons like the following
//
int numberOfFields = reader.getFieldCount();
// use this count to fetch all field information
// if required
//
for( int i=0; i<numberOfFields; i++) {
DBFField field = reader.getField( i);
// do something with it if you want
// refer the JavaDoc API reference for more details
//
System.out.println( field.getName());
}
// Now, lets us start reading the rows
//
Object []rowObjects;
while( (rowObjects = reader.nextRecord()) != null) {
for( int i=0; i<rowObjects.length; i++) {
System.out.println( rowObjects[i]);
}
}
// By now, we have itereated through all of the rows
inputStream.close();
}
catch( DBFException e) {
System.out.println( e.getMessage());
}
catch( IOException e) {
System.out.println( e.getMessage());
}
}
}
STEP 2: RUN IT ... :)
Saturday, August 23, 2014
How To Install Java on Ubuntu with Apt-Get
Introduction
As a lot of articles and programs require to have Java installed, this article will guide you through the process of installing and managing different versions of Java.Installing default JRE/JDK
This is the recommended and easiest option. This will install OpenJDK 6 on Ubuntu 12.04 and earlier and on 12.10+ it will install OpenJDK 7.Installing Java with
apt-get is easy. First, update the package index:sudo apt-get update
Then, check if Java is not already installed:java -version
If it returns "The program java can be found in the following
packages", Java hasn't been installed yet, so execute the following
command:sudo apt-get install default-jre
This will install the Java Runtime Environment (JRE). If you instead
need the Java Development Kit (JDK), which is usually needed to compile
Java applications (for example Apache Ant, Apache Maven, Eclipse and IntelliJ IDEA execute the following command:sudo apt-get install default-jdk
That is everything that is needed to install Java. All other steps are optional and must only be executed when needed.
Installing OpenJDK 7 (optional)
To install OpenJDK 7, execute the following command:sudo apt-get install openjdk-7-jre
This will install the Java Runtime Environment (JRE). If you instead
need the Java Development Kit (JDK), execute the following command:sudo apt-get install openjdk-7-jdk
Installing Oracle JDK (optional)
The Oracle JDK is the official JDK; however, it is no longer provided by Oracle as a default installation for Ubuntu.You can still install it using apt-get. To install any version, first execute the following commands:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
Then, depending on the version you want to install, execute one of the following commands:Oracle JDK 6
This is an old version but still in use.sudo apt-get install oracle-java6-installer
Oracle JDK 7
This is the latest stable version.sudo apt-get install oracle-java7-installer
Oracle JDK 8
This is a developer preview, the general release is scheduled for March 2014. This external article about Java 8 may help you to understand what it's all about.sudo apt-get install oracle-java8-installer
Managing Java (optional)
When there are multiple Java installations on your Droplet, the Java version to use as default can be chosen. To do this, execute the following command:sudo update-alternatives --config java
It will usually return something like this if you have 2 installations (if you have more, it will of course return more):There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-7-oracle/jre/bin/java 1062 auto mode
1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-7-oracle/jre/bin/java 1062 manual mode
Press enter to keep the current choice[*], or type selection number:
You can now choose the number to use as default. This can also be done for the Java compiler (javac):sudo update-alternatives --config javac
It is the same selection screen as the previous command and should be
used in the same way. This command can be executed for all other
commands which have different installations. In Java, this includes but
is not limited to: keytool, javadoc and jarsigner.Setting the "JAVA_HOME" environment variable
To set theJAVA_HOME environment variable, which is needed for some programs, first find out the path of your Java installation:sudo update-alternatives --config java
It returns something like:There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-7-oracle/jre/bin/java 1062 auto mode
1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-7-oracle/jre/bin/java 1062 manual mode
Press enter to keep the current choice[*], or type selection number:
The path of the installation is for each:/usr/lib/jvm/java-7-oracle/usr/lib/jvm/java-6-openjdk-amd64/usr/lib/jvm/java-7-oracle
/etc/environment:sudo nano /etc/environment
In this file, add the following line (replacing YOUR_PATH by the just copied path):JAVA_HOME="YOUR_PATH"
That should be enough to set the environment variable. Now reload this file:source /etc/environment
Test it by executing:echo $JAVA_HOME
If it returns the just set path, the environment variable has been
set successfully. If it doesn't, please make sure you followed all steps
correctly.Friday, May 30, 2014
Generate QR code using Java Example
QR code short for Quick Response Code is a two-dimensional matrix type barcode. Initially designed for the automotive industry has gained popularity in other areas such as retail packaging, storing web address and in smart phones due to its large storage capacity compared to standard UPC barcodes and fast readability.
Unlike the old barcode that was designed to be mechanically scanned by a narrow beam of light, the QR code is detected as a 2-dimensional digital image by a semiconductor image sensor and is then digitally analyzed by a programmed processor. The processor locates the three distinctive squares at the corners of the image, and normalizes image size, orientation, and angle of viewing, with the aid of a smaller square near the fourth corner. The small dots are then converted to binary numbers and validity checked with an error-correcting code. Nowadays there are scanner apps that uses the camera to scan these QR codes in our mobile phones and tablets.
The amount of data that can be stored in the QR Code symbol depends on the datatype
In this example we are going to learn how to generate a QR code from a String data. We take help of the open source library called ZXing((pronounced "zebra crossing") and QRGen that is built on top of Zxing library which makes it a breeze to generate the QR code in just a few lines of code. In your project you will need the following jar files
1
2
3
4
| Numeric only Max. 7,089 characters (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)Alphanumeric Max. 4,296 characters (0–9, A–Z [upper-case only], space, $, %, *, +, -, ., /, :)Binary/byte Max. 2,953 characters (8-bit bytes) (23624 bits)Kanji/Kana Max. 1,817 characters |
- core.jar
- javase.jar
- qrgen-1.1.jar
Application JSP - generateQRCode.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><meta name="robots" content="noindex,nofollow"/><title>Generate QR Code using QRGen and ZXing library</title><link rel="stylesheet" href="/resources/themes/master.css" type="text/css" /><link rel="stylesheet" type="text/css" /><script type="text/javascript"></script><script type="text/javascript"></script><script type="text/javascript"></script> <script src="/resources/scripts/mysamplecode.js" type="text/javascript"></script><script type="text/javascript"> $(document).ready(function() { $("#samplecode").validate({ rules: { qrText: "required" } }); }); </script> </head><body><div id="allContent"><%@include file="/header.jsp"%><% String qrText = request.getParameter("qrText");if(qrText == null){ qrText = "";}%><div id="myContent" style="width:50%;"> <form id="samplecode" name="samplecode" method="POST" action="generateQRCode.jsp"> <fieldset> <legend><b> QR Code Generator - Request </b></legend> <p> <label for="qrText"> Input Text for QR Code </label> <input id="qrText" type="text" name="qrText" size="50" value="<%= qrText %>" /> </p> <input id="generate" type="submit" value="Generate QR Code" /> </fieldset> <% if (!qrText.trim().equalsIgnoreCase("")) { %> <fieldset> <legend><b> QR Code Generator - Response </b></legend> <img src="../GenerateQRCode?qrText=<%= request.getParameter("qrText") %>"> </fieldset> <% } %> </form></div> <%@include file="/footer.jsp"%> </div></body></html> |
Source for Java Servlet - GenerateQRCode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
| package com.as400samplecode;import java.io.ByteArrayOutputStream;import java.io.IOException;import java.io.OutputStream;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import net.glxn.qrgen.QRCode;import net.glxn.qrgen.image.ImageType;public class GenerateQRCode extends HttpServlet { private static final long serialVersionUID = 1L; public GenerateQRCode() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String qrText = request.getParameter("qrText"); ByteArrayOutputStream out = QRCode.from(qrText).to(ImageType.PNG).withSize(300, 300).stream(); response.setContentType("image/png"); response.setContentLength(out.size()); OutputStream os = response.getOutputStream(); os.write(out.toByteArray()); os.flush(); os.close(); }} |
You can choose to either create a file or ByteArrayOutputStream
1
2
| File file = QRCode.from("Some input Text").file();ByteArrayOutputStream stream = QRCode.from("Some input Text").stream(); |
1
2
3
| QRCode.from("Some input Text").to(ImageType.JPG).file();QRCode.from("Some input Text").to(ImageType.GIF).file();QRCode.from("Some input Text").to(ImageType.PNG).file(); |
1
| QRCode.from("Some input Text").withSize(200, 200).file(); |
Subscribe to:
Posts (Atom)
