Friday, September 16, 2011

how to delete newline character from table

How to delete new line character from mysql table? replace new line character from table
I was facing a small problem...I was uploading a textfile data to a mysql database...my line tarminator is '\n'. in my comma seprated textfile each recode is written in a new line that is newline character at the end of each line...when I upload the data using load data infile....systax with the last column new line character is also added....I wanted to remove newline character form the database....
here is the final solution for this:


update table set field=replace(replace(field, "\n", ""), '\r', '')

Thursday, September 15, 2011

JSP Beginner Life Cycle of JSP

JSP (JavaServer Pages) - what is it?

JSP is a technology which enables the generation of dynamic web contents for a typical web application by separating the user interface generation from the actual content generation. This separation helps the page designers and content developers to do their respective tasks without interfering with each other. JSP can also be extended by adding Custom Tag Libraries to it.

A JSP page is just like a HTML web page that contains (strictly speaking we should say 'that may contain' as a plain static HTML page can also be saved as with a .jsp extension to make it a JSP page, but that's seldom used) additional pieces of code responsible for dynamic content generation. This additional code can utilize many Java APIs including JavaBeans, JDBC, EJB, and RMI for building the dynamic content. HTML part of the JSP page provides the layout in which the dynamically generated content is displayed.

Life Cycle of JSP (JavaServer Pages)

A JSP page is first converted into a Servlet and then that Servlet gets compiled and executed like any other Servlet. The translation of a JSP page into the corresponding Servlet is done by the JSP Engine of the underlying Web Container. The entire life cycle of a typical JSP page can be summarized as the following phases:-
 

  • Translation - In this phase the JSP page is translated into the corresponding Servlet. This translated Servlet is different from a normal Servlet only in the sense that it implements the interface javax.servlet.jsp.HttpJspPage. Well... if you look at this interface closely, you'll easily notice that a translated JSP page implements this interface just to have the JSP specific features. This HttpJspPage is just a wrapper of the Servlet interface as HttpJspPage interface extends the JspPage interafce and the JspPage interface extends the javax.servlet.Servlet interface. Thus, we see that the translated Servlet also internally implements the javax.servlet.Servlet interface (otherwise we would not have called it a servlet). In addition it implements few more interfaces to support the JSP technology.
  • Compilation - Once the JSP page has been translated into the corresponding Servlet, the next obvious step is to compile that Servlet.
  • Loading & Instantiation - As is the case with any compiled class (.class file), this servlet class also needs to be loaded into the memory before being used. The default classloader of the Web Conatiner will loads this class. Once the class is loaded, an instance of this class gets created. JspPage interaface contains the jspInit() method, which is used by the JSP Engine to initialize the newly created instance. This jspInit() method is just like the init() method of the Servlet and it's called only once during the entire life cycle of a JSP/Servlet.
  • Servicing Requests - _jspService() is the method which is called every time the JSP is requested to serve a request. This method normally executes in a separate thread of execution (provided we have selected Single Thread Model for the JSP) and the main JSP thread keeps waiting for other incoming requests. Every time a request arrives, the main JSP thread spawns a new thread and passes the request (incoming request) and response (new) objects to the _jspService() method which gets executed in the newly spawned thread.
  • Unloading - jspDestroy() method is called (almost always by the Web Container... Read a related article on why a JSP/Servlet writer shouln't call this method explicitly - Calling destroy() from init() in a Servlet >>) before the Web Container unloads the JSP instance. We normally keep code responsible for resource-reclaimation or clean-up activities in this method. After the execution of the jspDestroy() method, the JSP instance is marked for the garbage collection and the occupied memory is eventually reclaimed.

Monday, August 29, 2011

How to take database backup in java code

How to take database backup script in java code? Here is the sample java code to take database backup. According to this program, first get the tables list of a database, then export data of each table into separate txt file and save in the folder
//now backuping database..//
	try
	{
		String saveUrl="D://DataBackupWizard//DATABASE//";
String DB = "";
String url = "";
String uName = "";
String pwd = "";

Connection con=null;
Statement stm=null;
ResultSet rs=null;

File f=new File(saveUrl+dNames);
if(!f.exists())//create folder to store all txt file
{
f.mkdir();
}
String full_url="jdbc:mysql://"+url+"/"+dNames+"?autoReconnect=true";
Class.forName(DB);
con = DriverManager.getConnection(full_url,uName,pwd);
stm = con.createStatement();
if(done<tbList.size())
{
String tblName=(String)tbList.get(done);

File ft=new File(saveUrl+dNames+"//"+tblName+".txt");
if(ft.exists())// delete file if already exists
{
ft.delete();				
}

String query="SELECT * INTO OUTFILE 'D://DataBackupWizard//DATABASE//"+dNames+"//"+tblName+".txt' FIELDS TERMINATED BY '\t' FROM "+tblName;
System.out.println(query);
stm.executeQuery(query);
}

stm.close();
con.close();
}
catch(Exception Ex)
{
System.out.println(Ex);
}

Wednesday, August 17, 2011

How to make new window open at maximum size


Here is the tips for 'how to make new window open in maximum size using JavaScript'.

Basically we can’t control to open new pop up in new window with maximum size of browser, because OS setting of end user control.
But we can set the size of window wile opening new window. Here is example to open new pop op window in full screen:

Open new pop up window in full screen:
window.open('newWin.html','NewWindow','fullscreen=yes');

Another option to open new pop up window with dynamic size

 <a href="http://birenj2ee.blogspot.com/" onclick="window.open(this.href, 'child', 'height=' + screen.height + ',width=' + screen.width + ',resizable=yes'); return false">BirenJ2ee</a>

Another example to open pop up window with specific width and height:

window.open('http://birenj2ee.blogspot.com/','NewWindow','width=1000px,height=550px,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes, resizable=yes');

Android Guide Setup Eclipse and the Android SDK

Android Guide,
Setup Eclipse and the Android SDK  for beginner

How-To Install Android SDK On Windows, Integrate Android in Eclipse
Installing the Android SDK
The latest Android SDK for Windows, Mac and Linux can always be obtained from the following URI:
http://code.google.com/android/download.html
It only needs to be downloaded and unzipped to your preferred hdd-location.
The Android Development Tools (ADT)
Android provides an Eclipse plugin called ‘ADT’ to make programming and debugging easier. The ADT provides easy access to the LogCat, the Android-Manifest/Resource-Editor, File, Thread, and Heap Control, incoming call/sms simulation, etc… – since SDK-version m5 all for multiple emulator instances at the same time.


Installing the Eclipse Plugin (ADT)
To download and install the ADT plugin, follow the steps Google provides to developers:
1.       Start Eclipse, then select Help > Software Updates > Find and Install....
2.       In the dialog that appears, select Search for new features to install and press Next.
3.       Press New Remote Site.
4.       In the resulting dialog box, enter a name for the remote site (e.g. Android Plugin) and enter this as its URL:
https://dl-ssl.google.com/android/eclipse/ Press OK.
5.       You should now see the new site added to the search list (and checked). Press Finish.
6.       In the subsequent Search Results dialog box, select the checkbox for Android Plugin > Developer Tools. This will check both features: "Android Developer Tools", and "Android Editors". The Android Editors feature is optional, but recommended. If you choose to install it, you need the WST plugin mentioned earlier in this page.
Now press Next.
7.       Read the license agreement and then select Accept terms of the license agreement, if appropriate. Press Next.
8.       Press Finish.
9.       The ADT plugin is not signed; you can accept the installation anyway by pressing Install All.
10.   Restart Eclipse.
11.   After restart, update your Eclipse preferences to point to the SDK directory:
i)        Select Window > Preferences... to open the Preferences panel. (Mac OS X: Eclipse > Preferences)
ii)       Select Android from the left panel.
iii)     For the SDK Location in the main panel, press Browse... and locate the SDK directory.
iv)     Press Apply, then OK.

Updating the ADT Plugin
Updating the ADT Plugin follows the standard procedure of upgrading a common Eclipse plugin:
1)      Select Help > Software Updates > Find and Install....
2)      Select Search for updates of the currently installed features and press Finish.
3)      If any update for ADT is available, select and install.

Pathways of Web-based or java project development for beginner

About J2EE/Java programming in Market. market value of Java/J2EE/Mobile programming

Being a experience software programmer specially in Advanced Java, I am just sharing my views which can help lots of beginner who want to build their carrier in Java platform.
Web Based programming is taking innumerous market in 21 century, now the world & information is just sort of one click from us. Most of the information is available in net. Remaining of the information is circulating. And why not?, internet is one of the best, cheapest and most popular medium to market/flow the information to target audience.
And Web-based application/programs/software makes it to possible in very low cost.
Java/J2EE technology in one of the most popular and used technology to build such software.  For lay man, dynamic websites are created in advance technology having very high security.
There are lots of question for beginner:
Is Java Programming is very difficult?
I say Yes and No.
Yes its difficult, if you don't take it serious, if you don't understand its concept, if you don't practice.
No, its not so difficult as you think, if you just understand the concept of OOPs, just have more practice, or if you have background knowledge of c/C++, it will be very easy.

So, if you could understand concept of OOPS, class/Object/Methods, Interfaces etc, it will be very easy.


What are the possibilities pathways with in java?
There are lots of pathways with in java.
But from abstract level, they are:
Desktop/Standalone application: Java based GUI that runs in individual machine. For this, plain java files are used. Wed-based application: Based on Client-Server architecture. JSP/Servets are used. Mobile/J2ME application: Now a days mobile programming is becoming most popular. Most of the phone support java & lots of free application can be found. So mobile/J2ME would be one of the hot.

How do I start?
Very important question, but for all above java programming, basic concept of JAVA programming is required. So you must learn java, like classes, objects, methods, interface a concept of OOPS. Once you become familiar with these things you can adapt any further pathway. Yes don't think that u can't change programming from desktop application to web-based. You can switch any time and it won't be any problem. Because all are based on java programming only.

Which is most popular in the market?
Yes, now a days desktop/standalone application are not much used, however we can't say its not important. In some case it’s very useful. But according to current scenario, web based technology is getting popular, all the information are getting shared on internet, thus Web-based programming is most popular in market. Along with that J2ME/mobile programming is also popular.

Saturday, August 13, 2011

Convert array to arraylist in java with example

Here is the simple example, how to convert arrays to ArrayList or List in java.

Object[] array = new Object[]{"12","23","34"};
java.util.List list = Arrays.asList(array);