WebCam Video in Browser

Simple html to  stream webcam source in browser(getUserMedia supported browser). Supported Opera browser link is:

Copy the below code in html file and open that page in getUserMedia supported browsers.


<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<title>Web Cam Test In Browser</title>
<meta name="generator" content="editplus">
<meta name="author" content="Sreemanth Pulagam">
<script type="text/javascript" src="js/app.js"></script>
<video id="myvideo"  autoplay controls>
<script type="application/javascript">
var myVideo = $('myvideo');

console.log('getUserMedia supported in your browser');
function successCallback(stream){
myVideo.src= stream;
function errorCallback(error){

console.warn('getUserMedia not supported in your browser');


app.js Code

function $(id){
	return document.getElementById(id);
Posted in HTML5 | Leave a comment

Java Platform Debug Architecture Debug Example

package com.sreerama.debugging;

import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.Vector;

import com.sun.jdi.Bootstrap;
import com.sun.jdi.IncompatibleThreadStateException;
import com.sun.jdi.Method;
import com.sun.jdi.ObjectReference;
import com.sun.jdi.StackFrame;
import com.sun.jdi.ThreadReference;
import com.sun.jdi.VirtualMachine;
import com.sun.jdi.connect.AttachingConnector;
import com.sun.jdi.connect.Connector;
import com.sun.jdi.connect.Connector.Argument;
import com.sun.jdi.connect.IllegalConnectorArgumentsException;
import com.sun.jdi.event.Event;
import com.sun.jdi.event.EventQueue;
import com.sun.jdi.event.EventSet;
import com.sun.jdi.event.MethodEntryEvent;
import com.sun.jdi.request.EventRequestManager;
import com.sun.jdi.request.MethodEntryRequest;

public class JPDADebugger {
	private static final int SOCKET_ATTACH = 1;
	private VirtualMachine virtualMachine ;

	public void execute(String attachAddress, Vector includeClasses) {
		int index = attachAddress.indexOf(":");
		String hostName = attachAddress.substring(0, index);
		String port = attachAddress.substring(index + 1);
		if (includeClasses == null) {
			includeClasses = new Vector();
		String connectorName = "com.sun.jdi.SocketAttach";
		int connectorType = SOCKET_ATTACH;

		Connector connector = null;
		for (Connector connector2 : Bootstrap.virtualMachineManager()
				.allConnectors()) {
			if ( {
				connector = connector2;
		Map arguments = connector.defaultArguments();
		Argument host = arguments.get("hostname");
		Argument portArg = arguments.get("port");

		AttachingConnector attachingConnector = (AttachingConnector) connector;
		try {
			virtualMachine = attachingConnector.attach(arguments);
		} catch (IOException e) {
		} catch (IllegalConnectorArgumentsException e) {

		// / Event request Manager
		EventRequestManager eventRequestManager = virtualMachine
		for (Enumeration patterns = includeClasses.elements(); patterns
				.hasMoreElements();) {
			MethodEntryRequest methodEntryRequest = eventRequestManager
			String pattern = patterns.nextElement();

		EventQueue eventQueue = virtualMachine.eventQueue();
		boolean running = true;
		while (running) {
			EventSet eventSet = null;
			try {
				eventSet = eventQueue.remove();
			} catch (InterruptedException e) {
			for (Event event : eventSet) {
				if (event instanceof MethodEntryEvent) {
					processMethodEntryEvent((MethodEntryEvent) event);


	private void processMethodEntryEvent(MethodEntryEvent event) {
		Method method = event.method();
		String methodNameString =;
		ThreadReference thread = event.thread();
		try {
			List stackFrames = thread.frames();
			int level = 0;
			long calleId = 0;
			String calleClass = null;
			long callerId = 0;
			String callerClass = null;

			for (StackFrame stackFrame : stackFrames) {
				ObjectReference objectReference = stackFrame.thisObject();

				if (level == 0) {
					calleId = objectReference.uniqueID();
					calleClass = objectReference.referenceType().toString();
				if (level == 1) {
					callerId = objectReference.uniqueID();
					callerClass = objectReference.referenceType().toString();
				if (level > 1) {
			System.out.println("" + callerId + ":"
					+ callerClass + "" + methodNameString
					+ "" + calleId + ":" + calleClass
					+ "" +
					+ "");

		} catch (IncompatibleThreadStateException e) {

Test Program

package com.sreerama.debugging;

import java.util.Vector;

public class JPDADebuggerTest {

	public static void main(String[] args) {
		JPDADebugger debugger = new JPDADebugger();
		Vector classes = new Vector();
		debugger.execute("localhost:8124", classes);

Changes in tomcat catalina.bat file

set JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG% -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=8124,suspend=n

add bold text need to add for catalina.bat file (%TOMCAT_HOME%/bin/catalina.bat)

Posted in JPDA Example | Leave a comment

Hibernate Exception org.hibernate.exception.SQLGrammarException: ORA-00926: missing VALUES keyword

Hibernate: select hibernate_sequence.nextval from dual
Hibernate: insert into ITEM (NAME, PRICE, ID) values (?, ?, ?)
Hibernate: insert into ITEM-IMAGE (ITEM_ID, IMAGE_NAME) values (?, ?)
Hibernate: insert into ITEM-IMAGE (ITEM_ID, IMAGE_NAME) values (?, ?)
Hibernate: insert into ITEM-IMAGE (ITEM_ID, IMAGE_NAME) values (?, ?)
Hibernate: insert into ITEM-IMAGE (ITEM_ID, IMAGE_NAME) values (?, ?)
Hibernate: insert into ITEM-IMAGE (ITEM_ID, IMAGE_NAME) values (?, ?)
Hibernate: insert into ITEM-IMAGE (ITEM_ID, IMAGE_NAME) values (?, ?)
Hibernate: insert into ITEM-IMAGE (ITEM_ID, IMAGE_NAME) values (?, ?)
Hibernate: insert into ITEM-IMAGE (ITEM_ID, IMAGE_NAME) values (?, ?)
Hibernate: insert into ITEM-IMAGE (ITEM_ID, IMAGE_NAME) values (?, ?)
Hibernate: insert into ITEM-IMAGE (ITEM_ID, IMAGE_NAME) values (?, ?)

Exception in thread “main” org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(
at org.hibernate.exception.JDBCExceptionHelper.convert(
at org.hibernate.jdbc.AbstractBatcher.executeBatch(
at org.hibernate.engine.ActionQueue.executeActions(
at org.hibernate.engine.ActionQueue.executeActions(
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(
at org.hibernate.impl.SessionImpl.list(
at org.hibernate.impl.QueryImpl.list(
at com.sreerama.hibernateexamples.test.ItemTest.main(
Caused by: java.sql.BatchUpdateException: ORA-00926: missing VALUES keyword

Here Issue is ORA-00926:

Actual issue is  sql query has error –>insert into ITEM-IMAGE (ITEM_ID, IMAGE_NAME) values (?, ?)

Table name should not have ITEM-IMAGE, can be ITEM_IMAGE

*. hbm.xml file

wrong one

<set name=”images” table=“ITEM-IMAGE” lazy=”false”>
<key column=”ITEM_ID”></key>
<element column=”IMAGE_NAME” type=”string” not-null=”false”></element>

correct one is below.

<set name=”images” table=“ITEM_IMAGE” lazy=”false”>
<key column=”ITEM_ID”></key>
<element column=”IMAGE_NAME” type=”string” not-null=”false”></element>

Posted in Hibernate | Leave a comment

Finding sum of positive numbers and negative numbers from a sql table


Using decode:

select sum(decode(sign(blocks),1,blocks,0)) as positive_sum , sum(decode(sign(blocks),-1,blocks,0)) as negative_sum from sysfiles

Using case:

select  sum( case when blocks > 0 then blocks else 0 end )as credit  , sum (case when blocks < 0 then blocks else 0 end) as debit from sysfiles

Posted in sql | Leave a comment

Program to find no of Occurances of word.(Simple way)

Code to find the no of occurrences of specific word

package com.sree.file;

public class SpecificWordCountFinder {

	public static void main(String[] args) {
		// find String
		String toFindString = "Java";
		// Content to Find
		String content = "This is very simple tricky Java program ."
				+ "Java is OOP.Java is both compile and interpreted. Java built in multithreaded";

		 * formula to find occurences = (total length - after replace all * with find string content length)/ findstring length
		long totalLength = content.length();
		long inputStringLength = toFindString.length();

		String output = content.replaceAll(toFindString, "");
		long outputLength = output.length();
		System.out.println("No of occurances of word" + toFindString + "is :"
				+ (totalLength - outputLength) / inputStringLength);
Posted in java | Leave a comment

Welcome to Infocrate

This site is dedicated to java related articles.

Posted in Uncategorized | Leave a comment

simple JNI (Java Native Interface) example

public class HelloWorld
private native void print();
public static void main(String[] args)
HelloWorld hw = new Helloworld();

1) compile the

2) create a native method Header file
javah -jni HelloWorld
after this command a file named HelloWorld.h is created in the folder, don’t change that file

3) write a native method implementaiton(HelloWorld.c)

#include "HelloWorld.h"

Java_HelloWorld_print(JNIEnv *env, jobject obj)
return 0;

4) compile the C source
cl -I”c:\program files\java\java1.7\include” -I”c:\program files\java\java1.7\include\win32″ -LD Helloworld.c -FeHelloWorld.dll

5) now run the java program
java HelloWorld

Posted in java | Leave a comment