tag:blogger.com,1999:blog-28629161394286581162024-02-20T16:54:17.628+05:30Santhosh's Tech BlogHere I've shared my random knowledge gatherings on java, C#.Net, Performance scalability tuning concepts, Tweaks, tricks, hacks, programming Logics.Santhosh Kannanhttp://www.blogger.com/profile/05049496959767320304noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-2862916139428658116.post-90929834437213618102013-08-02T18:47:00.001+05:302013-08-02T18:47:55.053+05:30Unhide all folders and files in USB drive<div dir="ltr" style="text-align: left;" trbidi="on">
Recently I got my flash drive affected with a virus and all the folders were hidden and a shortcuts were created. I removed the virus program running in my system with avg antivirus and used the below command to show all the hidden directory<br />
<br />
<b>attrib -s -h /s /d *.*</b><br />
<b><br /></b>
You can execute this command at the root folder<br />
<b><br /></b>
This dos command just remove the hidden attribute from all the folders.</div>
Santhosh Kannanhttp://www.blogger.com/profile/05049496959767320304noreply@blogger.com0tag:blogger.com,1999:blog-2862916139428658116.post-9661057277895523732012-01-12T17:02:00.002+05:302012-03-08T09:26:19.551+05:30HTTP load balancing using Apache and Mod_jk<div dir="ltr" style="text-align: left;" trbidi="on"><style type="text/css">
pre { font-family: "Liberation Mono","Courier New",monospace; }p { margin-bottom: 0.08in; }td p { margin-bottom: 0in; }h3 { margin-bottom: 0.08in; }h3.western { font-family: "Liberation Serif","Times New Roman",serif; }h3.cjk { font-family: "DejaVu LGC Sans"; }h3.ctl { font-family: "DejaVu LGC Sans"; }code { font-family: "Liberation Mono","Courier New",monospace; }
</style> <div align="JUSTIFY" style="line-height: 150%; margin-bottom: 0in;"><span style="font-family: arial,sans-serif;"><span style="font-size: small;"> </span></span><span style="font-family: arial,sans-serif;"><span style="font-size: small;"><b></b></span></span><span style="font-family: arial,sans-serif;"><span style="font-size: small;"><b><br />
</b></span></span></div><div style="line-height: 150%; margin-bottom: 0in;"><b><span style="font-family: arial,sans-serif;"><span style="font-size: small;">Environment</span></span></b></div><div style="line-height: 150%; margin-bottom: 0in;"><span style="font-family: arial,sans-serif;"><span style="font-size: small;">J2EE Application deployed in JBOSS AS 5. Same such Jboss instances are clustered. If we need to load balance the HTTP requests across the various jboss instances the following steps can be followed. This post basically depicts the configurations done to setup a HTTP load balancer.</span></span></div><div style="line-height: 150%; margin-bottom: 0in;"><br />
</div><div style="line-height: 150%; margin-bottom: 0in;"><span style="font-family: arial,sans-serif;"><span style="font-size: small;"><b>Software Packages Required</b></span></span></div><div style="line-height: 150%; margin-bottom: 0in;"><br />
</div><ul><li><div style="line-height: 150%; margin-bottom: 0in;"><span style="font-family: arial,sans-serif;"><span style="font-size: small;">Apache 2.2.x</span></span></div></li>
<li><div style="line-height: 150%; margin-bottom: 0in;"><a href="" name="clustering-http-download"></a> <span style="font-family: arial,sans-serif;"><span style="font-size: small;">mod_jk 1.2.x</span></span></div></li>
</ul><div style="line-height: 150%; margin-bottom: 0in;"><br />
</div><div style="line-height: 150%; margin-bottom: 0in;"><span style="font-family: arial,sans-serif;"><span style="font-size: small;">Apache server can be downloaded directly from Apache web site at </span></span><code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">http://httpd.apache.org/</span></span></code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">. </span></span> </div><div style="line-height: 150%; margin-bottom: 0in;"><br />
</div><div style="line-height: 150%; margin-bottom: 0in;"><a href="" name="clustering-http-download1"></a> <span style="font-family: arial,sans-serif;"><span style="font-size: small;">The mod_jk 1.2.x binary can be downloaded from </span></span><code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">http://www.apache.org/dist/jakarta/tomcat-connectors/jk/binaries/</span></span></code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">. Rename the downloaded file to </span></span><code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">mod_jk.so</span></span></code><span style="font-family: arial,sans-serif;"><span style="font-size: small;"> and copy it under </span></span><code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">APACHE_HOME/modules/</span></span></code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">.</span></span></div><div align="JUSTIFY" style="line-height: 150%; margin-bottom: 0in;"><br />
</div><div style="line-height: 150%; margin-bottom: 0in;"><a href="" name="d0e3013"></a> <span style="font-family: arial,sans-serif;"><span style="font-size: small;"><b>Configure Apache to load mod_jk</b></span></span></div><div style="line-height: 150%;"><a href="" name="d0e30131"></a><span style="font-family: arial,sans-serif;"><span style="font-size: small;">Step1. Modify APACHE_HOME/conf/httpd.conf and add a single line at the end of the file:</span></span></div><pre style="line-height: 150%;"><a href="" name="d0e30132"></a><span style="font-family: arial,sans-serif;"><span style="font-size: small;"># Include mod_jk's specific configuration file </span></span></pre><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: small;">Include conf/mod-jk.conf </span></span> </div><div style="line-height: 150%;"><a href="" name="d0e30133"></a><span style="font-family: arial,sans-serif;"><span style="font-size: small;">Step2. Create a new file named </span></span><code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">APACHE_HOME/conf/mod-jk.conf</span></span></code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">:</span></span></div><pre style="line-height: 0.07in;"><a href="" name="d0e30134"></a><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;"># Load mod_jk module</span></span>
<span style="font-family: arial,sans-serif;"><span style="font-size: x-small;"># Specify the filename of the mod_jk lib</span></span>
<span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">LoadModule jk_module modules/mod_jk.so</span></span>
<span style="font-family: arial,sans-serif;"><span style="font-size: x-small;"># Where to find workers.properties</span></span>
<span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">JkWorkersFile conf/workers.properties</span></span>
<span style="font-family: arial,sans-serif;"><span style="font-size: x-small;"># Where to put jk logs</span></span>
<span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">JkLogFile logs/mod_jk.log</span></span>
<span style="font-family: arial,sans-serif;"><span style="font-size: x-small;"># Set the jk log level [debug/error/info]</span></span>
<span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">JkLogLevel info </span></span>
<span style="font-family: arial,sans-serif;"><span style="font-size: x-small;"># Select the log format</span></span>
<span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"</span></span>
<span style="font-family: arial,sans-serif;"><span style="font-size: x-small;"># Mount your applications</span></span>
<span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">JkMount /application/* loadbalancer</span></span>
<a href="" name="clustering-http-nodes"></a><span style="font-family: arial,sans-serif;"><span style="font-size: small;"><b>Configure worker nodes in mod_jk</b></span></span></pre><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: small;"> The mod_jk workers file </span></span><code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">conf/workers.properties should be configured</span></span></code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">. This file specifies where the different Servlet containers are located and how calls should be load-balanced across them. The configuration file contains one section for each target servlet container and one global section. For a two nodes setup, the file could look like this:</span></span></div><div style="line-height: 150%; margin-bottom: 0in;"><br />
</div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;"># Define list of workers that will be used</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;"># for mapping requests</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">worker.list=loadbalancer,status</span></span></div><div style="line-height: 150%;"><br />
</div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;"># Define Node1</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;"># modify the host as your host IP or DNS name.</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">worker.node1.port=8009</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">worker.node1.host=192.168.2.50</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">worker.node1.type=ajp13</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">worker.node1.lbfactor=1</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">worker.node1.cachesize=10</span></span></div><div style="line-height: 150%;"><br />
</div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;"># Define Node2</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;"># modify the host as your host IP or DNS name.</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">worker.node2.port=8009</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">worker.node2.host= 192.168.2.52</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">worker.node2.type=ajp13</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">worker.node2.lbfactor=1</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">worker.node2.cachesize=10</span></span></div><div style="line-height: 150%;"><br />
</div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;"># Load-balancing behaviour</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">worker.loadbalancer.type=lb</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">worker.loadbalancer.balance_workers=node1,node2</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">worker.loadbalancer.sticky_session=1</span></span></div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">#worker.list=loadbalancer</span></span></div><div style="line-height: 150%;"><br />
</div><div style="line-height: 150%;"><br />
</div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;"># Status worker for managing load balancer</span></span></div><div style="line-height: 150%;"><br />
</div><div style="line-height: 150%;"><span style="font-family: arial,sans-serif;"><span style="font-size: x-small;">worker.status.type=status</span></span></div><div style="line-height: 150%; margin-bottom: 0in;"><br />
</div><div align="JUSTIFY" style="line-height: 150%; margin-bottom: 0in;"><span style="font-family: arial,sans-serif;"><span style="font-size: small;"><b>Sticky Session</b></span></span></div><div align="JUSTIFY" style="line-height: 150%; margin-bottom: 0in;"><a href="" name="clustering-http-nodes1"></a> <span style="font-family: arial,sans-serif;"><span style="font-size: small;"> The </span></span><code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">sticky_session</span></span></code><span style="font-family: arial,sans-serif;"><span style="font-size: small;"> property specifies the cluster behavior for HTTP sessions. If </span></span><code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">worker.loadbalancer.sticky_session=0</span></span></code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">, each request will be load balanced between node1 and node2; i.e., different requests for the same session will go to different servers. But when a user opens a session on one server, it is always necessary to always forward this user's requests to the same server, as long as that server is available. This is called a "sticky session", as the client is always using the same server he reached on his first request. To enable session stickiness, you need to set </span></span><code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">worker.loadbalancer.sticky_session</span></span></code><span style="font-family: arial,sans-serif;"><span style="font-size: small;"> to 1.</span></span></div><div align="JUSTIFY" style="line-height: 150%; margin-bottom: 0in;"><br />
</div><div align="JUSTIFY" style="line-height: 150%; margin-bottom: 0in;"><span style="font-family: arial,sans-serif;"><span style="font-size: small;"><b>Lbfactor</b></span></span></div><div align="JUSTIFY" style="line-height: 150%; margin-bottom: 0in;"><a href="" name="clustering-http-nodes2"></a> <span style="font-family: arial,sans-serif;"><span style="font-size: small;">The </span></span><code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">lbfactor</span></span></code><span style="font-family: arial,sans-serif;"><span style="font-size: small;"> attribute is the load-balancing factor for a specific worker. It is used to define the priority (or weight) a node should have over other nodes. The higher this number is for a given worker relative to the other workers, the more HTTP requests the worker will receive. This setting can be used to differentiate servers with different processing power.</span></span></div><div style="line-height: 150%; margin-bottom: 0in;"><br />
</div><div style="line-height: 150%; margin-bottom: 0in; page-break-before: always;"><br />
</div><h3 class="western" style="line-height: 150%;"><a href="" name="clustering-http-jboss"></a> <span style="font-family: arial,sans-serif;"><span style="font-size: small;">Configuring JBoss to work with mod_jk</span></span></h3><div style="line-height: 150%;"><a href="" name="clustering-http-jboss1"></a><span style="font-family: arial,sans-serif;"><span style="font-size: small;">On each clustered JBoss node, we have to name the node according to the name specified in </span></span><code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">workers.properties</span></span></code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">. For instance, on JBoss instance node1, edit the </span></span><code><span style="font-family: arial,sans-serif;"><span style="font-size: small;"><i><span style="background: none repeat scroll 0% 0% transparent;">JBOSS_HOME/server/all/deploy/jbossweb.sar/server.xml</span></i></span></span></code><span style="font-family: arial,sans-serif;"><span style="font-size: small;"><span style="background: none repeat scroll 0% 0% transparent;"> file </span></span></span><span style="font-family: arial,sans-serif;"><span style="font-size: small;">Locate the </span></span><code><span style="font-family: arial,sans-serif;"><span style="font-size: small;"><Engine></span></span></code><span style="font-family: arial,sans-serif;"><span style="font-size: small;"> element and add an attribute </span></span><code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">jvmRoute</span></span></code><span style="font-family: arial,sans-serif;"><span style="font-size: small;">:</span></span></div><div style="line-height: 150%;"><br />
<br />
</div><pre style="line-height: 150%;"><a href="" name="clustering-http-jboss2"></a><span style="font-family: arial,sans-serif;"><span style="font-size: small;"><Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1"></span></span>
<span style="font-family: arial,sans-serif;"><span style="font-size: small;">... ...</span></span>
<span style="font-family: arial,sans-serif;"><span style="font-size: small;"></Engine></span></span></pre></div>Santhosh Kannanhttp://www.blogger.com/profile/05049496959767320304noreply@blogger.com0tag:blogger.com,1999:blog-2862916139428658116.post-23308464961812041782012-01-12T16:02:00.000+05:302012-01-12T16:06:46.179+05:30MySQL Server performance tuning<div dir="ltr" style="text-align: left;" trbidi="on"><style type="text/css">
p { margin-bottom: 0.08in; }code { font-family: "Liberation Mono","Courier New",monospace; }
</style> <br />
<div align="CENTER"><span style="color: black;"><b><br />
</b></span> </div><div align="CENTER"><div style="text-align: justify;"><span style="color: black;">Tuning the following parameters in mysql configuration file were found very efficient. These below parameters should be configured in my.cnf(linux) and my.ini(windows)</span></div><div style="text-align: justify;"><span style="color: black;"> </span></div></div><div style="text-decoration: none;"><span style="color: black;"><b>table_cache</b></span></div><div style="text-decoration: none;"><span style="color: black;">It changes the maximum number of files the server keeps open. Opening tables is expensive.</span></div><div style="text-decoration: none;"><span style="color: black;">Each time MySQL accesses a table, it places it in the cache. If the system accesses many tables, it is faster to have these in the cache</span></div><span style="color: navy;"><u><a href="http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_table_cache">table_cache</a></u></span><span style="color: black;"><span style="text-decoration: none;"> is related to </span></span><span style="color: navy;"><u><a href="http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_connections">max_connections</a></u></span><span style="color: black;"><span style="text-decoration: none;">. For example, for 200 concurrent running connections, its optimal to have a table cache size of at least </span></span><code><span style="color: black;"><span style="text-decoration: none;">200 * </span></span></code><i><span style="color: black;"><span style="text-decoration: none;">N</span></span></i><span style="color: black;"><span style="text-decoration: none;">, where </span></span><code><span style="color: black;"><span style="text-decoration: none;">N</span></span></code><span style="color: black;"><span style="text-decoration: none;"> is the maximum number of tables per join in any of the queries which you execute. You must also reserve some extra file descriptors for temporary tables and files. </span></span> <br />
<div style="text-decoration: none;"><br />
<br />
</div><div style="text-decoration: none;"><span style="color: black;"><b>sort_buffer_size</b></span></div><div style="text-decoration: none;"><span style="color: black;">It is the buffer memory used to process the sort queries. It has negative impact if increased too much with low volume of data. Optimum size is 2MB .</span></div><div style="text-decoration: none;"><br />
<br />
</div><div style="text-decoration: none;"><span style="color: black;"><b>read_buffer_size</b></span></div><div style="text-decoration: none;"><span style="color: black;">It is the buffer memory used to process the sort queries. It has negative impact if increased too much with low volume of data. Optimum size is 2MB .</span></div><div style="text-decoration: none;"><br />
<br />
</div><div style="text-decoration: none;"><span style="color: black;"><b>thread_cache_size</b></span></div><div style="text-decoration: none;"><span style="color: black;">Thread creation/destructions can be expensive, which happen at each connect/disconnect.</span></div><div style="text-decoration: none;"><br />
<br />
</div><div style="text-decoration: none;"><span style="color: black;"><b>query_cache_size</b></span></div><div style="text-decoration: none;"><span style="color: black;">Increasing query_cache_size improves the performance while executing frequent read queries.</span></div><div style="text-decoration: none;"><br />
<br />
</div><div style="text-decoration: none;"><span style="color: black;"><b>thread_concurrency</b></span></div><div style="text-decoration: none;"><span style="color: black;">No of threads executing at a time. It should be tuned based on the CPU the application is deployed.</span></div><div style="text-decoration: none;"><span style="color: black;">optimum value=number of CPU's*2 </span> </div><div style="text-decoration: none;"><br />
<br />
</div><div style="text-decoration: none;"><span style="color: black;"><b>innodb_flush_log_at_trx_commit </b></span> </div><div style="text-decoration: none;"><span style="color: black;">This determines the frequency of log flushing to disk.</span></div><span style="color: black;"><span style="text-decoration: none;">If the value of </span></span><span style="color: navy;"><u><a href="http://dev.mysql.com/doc/refman/4.1/en/innodb-parameters.html#sysvar_innodb_flush_log_at_trx_commit">innodb_flush_log_at_trx_commit</a></u></span><span style="color: black;"><span style="text-decoration: none;"> is 0, the log buffer is written out to the log file once per second and the flush to disk operation is performed on the log file, but nothing is done at a transaction commit. </span></span> <br />
<div style="text-decoration: none;"><span style="color: black;">When the value is 1, the log buffer is written out to the log file at each transaction commit and the flush to disk operation is performed on the log file. </span> </div><div style="text-decoration: none;"><span style="color: black;">When the value is 2, the log buffer is written out to the file at each commit, but the flush to disk operation is not performed on it. However, the flushing on the log file takes place once per second also when the value is 2. </span> </div><div style="text-decoration: none;"><br />
<br />
</div><b><span style="color: black;"><span style="text-decoration: none;">innodb_buffer_pool_size</span></span></b><span style="color: black;"><span style="text-decoration: none;"> </span></span> <br />
<span style="color: black;"><span style="text-decoration: none;">The size in bytes of the memory buffer </span></span><code><span style="color: black;"><span style="text-decoration: none;">InnoDB</span></span></code><span style="color: black;"><span style="text-decoration: none;"> uses to cache data and indexes of its tables. The default value is 8MB. The larger this value is set, the less disk I/O is needed to access data in tables. On a dedicated database server, it can be set up to 80% of the machine physical memory size. </span></span> </div>Santhosh Kannanhttp://www.blogger.com/profile/05049496959767320304noreply@blogger.com0tag:blogger.com,1999:blog-2862916139428658116.post-69422022383655521782012-01-10T17:51:00.002+05:302012-03-08T09:26:50.891+05:30Remove all .svn files<div dir="ltr" style="text-align: left;" trbidi="on"><div style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: small;">While checkout from SVN repositary the repositary information is present in the directory .svn. While delivering project/source code we have to remove such .svn directories.</span></div><div style="font-family: Arial,Helvetica,sans-serif;"><br />
</div><div style="font-family: Arial,Helvetica,sans-serif;"><span style="font-size: small;">Instead of removing each .svn folder manually execute this command to delete all .svn folders recursively.</span></div><br />
<span style="color: #351c75; font-family: "Trebuchet MS", sans-serif; font-size: large;"><b><code>find ./ -name ".svn" | xargs rm -Rf</code></b> </span><br />
<br />
<br />
<br />
<br />
<br />
</div>Santhosh Kannanhttp://www.blogger.com/profile/05049496959767320304noreply@blogger.com0tag:blogger.com,1999:blog-2862916139428658116.post-6242122141829925592012-01-09T23:31:00.003+05:302012-03-08T09:27:07.131+05:30Screenshot using C# .NET<div dir="ltr" style="text-align: left;" trbidi="on"><ul style="text-align: left;"><li> Create a window application using MS Visual Studio. </li>
<li>Add a Picture box and a Button.</li>
</ul><br />
<br />
<br />
<u>Source Code</u><br />
<div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;">using System;</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;">using System.Collections.Generic;</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;">using System.ComponentModel;</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;">using System.Data;</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;">using System.Drawing;</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;">using System.Drawing.Imaging ;</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;">using System.Text;</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;">using System.Windows.Forms;</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"><br />
</span><span style="color: black;"> </span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;">namespace screen_shot</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;">{</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"> public partial class Form1 : Form</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"> {</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"> public Form1()</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"> {</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"> InitializeComponent();</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"> }</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"><br />
</span><span style="color: black;"> </span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"> private void button1_Click(object sender, EventArgs e)</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"> {</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"> int scrwidth = Screen.GetBounds(new Point(0, 0)).Width;</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"> int scrheight = Screen.GetBounds(new Point(0, 0)).Height;</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"> Bitmap bmp = new Bitmap(scrwidth, scrheight);</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"> Graphics gfx = Graphics.FromImage((Image)bmp);</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"> gfx.CopyFromScreen(0,0,0,0,new Size(scrwidth,scrheight));</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"> bmp.Save(@"c:\test.jpg",ImageFormat.Jpeg);</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"> }</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;"> }</span></span></div><div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;">}</span></span></div></div>Santhosh Kannanhttp://www.blogger.com/profile/05049496959767320304noreply@blogger.com0tag:blogger.com,1999:blog-2862916139428658116.post-79766884673799127372012-01-09T22:58:00.003+05:302012-03-08T09:27:20.633+05:30Read From Excel file - Java<div dir="ltr" style="text-align: left;" trbidi="on">Here I have used JXL API to read Excel file. It can be downloaded from <a href="http://jexcelapi.sourceforge.net/" target="_blank">JXL API download</a><br />
<br />
<u>Source Code</u><br />
<br />
<div style="color: purple; font-family: "Trebuchet MS",sans-serif;"><span style="font-size: small;"><span style="color: black;">import java.io.File;</span></span><br />
<span style="font-size: small;"><span style="color: black;">import java.io.IOException;</span></span><br />
<span style="font-size: small;"><span style="color: black;">import jxl.Cell;</span></span><br />
<span style="font-size: small;"><span style="color: black;">import jxl.Sheet;</span></span><br />
<span style="font-size: small;"><span style="color: black;">import jxl.Workbook;</span></span><br />
<span style="font-size: small;"><span style="color: black;">import jxl.read.biff.BiffException;</span></span><br />
<span style="font-size: small;"><span style="color: black;">public class ReadExcel</span></span><br />
<span style="font-size: small;"><span style="color: black;">{</span></span><br />
<span style="font-size: small;"><span style="color: black;"> private String inputFile;</span></span><br />
<span style="font-size: small;"><span style="color: black;"><br />
</span><span style="color: black;"> </span></span><br />
<span style="font-size: small;"><span style="color: black;"> public void setInputFile(String inputFile)</span></span><br />
<span style="font-size: small;"><span style="color: black;"> {</span></span><br />
<span style="font-size: small;"><span style="color: black;"> this.inputFile = inputFile;</span></span><br />
<span style="font-size: small;"><span style="color: black;"> }</span></span><br />
<span style="font-size: small;"><span style="color: black;"> public void read() throws IOException</span></span><br />
<span style="font-size: small;"><span style="color: black;"> {</span></span><br />
<span style="font-size: small;"><span style="color: black;"> File inputWorkbook = new File(inputFile);</span></span><br />
<span style="font-size: small;"><span style="color: black;"> Workbook w;</span></span><br />
<span style="font-size: small;"><span style="color: black;"> try</span></span><br />
<span style="font-size: small;"><span style="color: black;"> {</span></span><br />
<span style="font-size: small;"><span style="color: black;"> w = Workbook.getWorkbook(inputWorkbook);</span></span><br />
<span style="font-size: small;"><span style="color: black;"> // Get the first sheet</span></span><br />
<span style="font-size: small;"><span style="color: black;"> Sheet sheet = w.getSheet(0);</span></span><br />
<span style="font-size: small;"><span style="color: black;"><br />
</span><span style="color: black;"> </span></span><br />
<span style="font-size: small;"><span style="color: black;"> for (int j = 0; j < sheet.getRows(); j++)</span></span><br />
<span style="font-size: small;"><span style="color: black;"> {</span></span><br />
<span style="font-size: small;"><span style="color: black;"> for (int i = 0; i < sheet.getColumns(); i++)</span></span><br />
<span style="font-size: small;"><span style="color: black;"> {</span></span><br />
<span style="font-size: small;"><span style="color: black;"> Cell cell = sheet.getCell(i, j);</span></span><br />
<span style="font-size: small;"><span style="color: black;"> System.out.print(cell.getContents()+"\t|\t");</span></span><br />
<span style="font-size: small;"><span style="color: black;"> </span></span><br />
<span style="font-size: small;"><span style="color: black;"> // here you can use sql Queries/other code to do insertion of what ever fields you want</span></span><br />
<span style="font-size: small;"><span style="color: black;"> </span></span><br />
<span style="font-size: small;"><span style="color: black;"> }</span></span><br />
<span style="font-size: small;"><span style="color: black;"> System.out.println();</span></span><br />
<span style="font-size: small;"><span style="color: black;"> }</span></span><br />
<span style="font-size: small;"><span style="color: black;"> } catch (BiffException e)</span></span><br />
<span style="font-size: small;"><span style="color: black;"> {</span></span><br />
<span style="font-size: small;"><span style="color: black;"> e.printStackTrace();</span></span><br />
<span style="font-size: small;"><span style="color: black;"> }</span></span><br />
<span style="font-size: small;"><span style="color: black;"> }</span></span><br />
<span style="font-size: small;"><span style="color: black;"><br />
</span><span style="color: black;"> </span></span><br />
<span style="font-size: small;"><span style="color: black;"> public static void main(String[] args) throws IOException</span></span><br />
<span style="font-size: small;"><span style="color: black;"> {</span></span><br />
<span style="font-size: small;"><span style="color: black;"> ReadExcel test = new ReadExcel();</span></span><br />
<span style="font-size: small;"><span style="color: black;"> test.setInputFile("c:\\namelist.xls");</span></span><br />
<span style="font-size: small;"><span style="color: black;"> test.read();</span></span><br />
<span style="font-size: small;"><span style="color: black;"> }</span></span><br />
<span style="font-size: small;"><span style="color: black;">}</span> </span></div><div style="color: purple;"><br />
</div><br />
</div>Santhosh Kannanhttp://www.blogger.com/profile/05049496959767320304noreply@blogger.com0tag:blogger.com,1999:blog-2862916139428658116.post-91853487906581190742012-01-09T09:17:00.000+05:302012-01-09T09:17:08.147+05:30SQL Injection<div dir="ltr" style="text-align: left;" trbidi="on">SQL Injection is a web attack to sneak into a website. </div>Santhosh Kannanhttp://www.blogger.com/profile/05049496959767320304noreply@blogger.com0