Friday, February 27, 2015

GIT Commands

Mkdir testdir
Cd testdir
Git clone wsdp@  for checkout
Git log
Git status
Vi testfile.xml
Git add testfile.xml
Git status
Git config --global user.email "dbialke@worldsync.com"
Git config --global user.name "Daniel Bialke"

Git commit
Enter the comment
Git status
Git reset HEAD^
Git status
Rm testfile.xml
Git pull
Git clone git@code:playground.git
Cd playground
Git log
Git add ABC
Git status
Git add abba.txt
Git status
Git commit -m "fixed bug"
Git log
Git push
Echo "ABC">>1.txt
Git add .
Git commit  -m "Change 1"
Echo "123.txt">>1.txt
Git diff
Git add .
Git commit -m "Change 2"
Git status
Git log
Git branch
Man git-branch
Git log
Git checkout -b dev_change1 98989898998989
Git log
Git branch
Git log
Git show 898989hash
Git log
Git show 90809770hash
Git checkout master
Git log
Git log 1.txt
Git checkout 65555hash 1.txt
Git log
Git checkout 8989898hash pox.xml
Git

Git tag|grep demo
Git checkout -b "demo_branch" demo_tag
Git log
Git add .
Git pull
Git push

Git show

JBOSS 7 File system

Properties:
-----------------------
/opt/dev2adm/jboss-as-7.1.1.Final/modules/com/oneworldsync/conf/1syncprops/main

Logs:
----------------------
/opt/dev2adm/jboss-as-7.1.1.Final/standalone/log/AppLog

Executable
---------------------
/opt/dev2adm/jboss-as-7.1.1.Final/bin

Deployments
--------------------
/opt/dev2adm/jboss-as-7.1.1.Final/standalone/deployments

LOG Level:
------------------
FATAL
ERROR
WARN
INFO
DEBUG


 /opt/httpd-2.2.22/bin/httpd -f /opt/httpd-2.2.22/conf/httpd.conf -k start
 /opt/httpd-2.2.22/bin/httpd -f /opt/httpd-2.2.22/conf/httpd.conf -k stop


-J-Djavax.net.ssl.trustStrore=C:/Users/sb26313/Desktop/jssecacerts

Wednesday, December 3, 2014

Ways to Loop / Iterate A List In Java

Here are four ways to loop a List in Java.
1.    Iterator loop
2.    For loop
3.    For loop (Advance)
4.    While loop
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class ArrayToList {
     public static void main(String[] argv) {

        String sArray[] = new String[] { "Array 1", "Array 2", "Array 3" };
        // convert array to list
        List<String> lList = Arrays.asList(sArray);
        // iterator loop
        System.out.println("#1 iterator");
        Iterator<String> iterator = lList.iterator();
        while (iterator.hasNext()) {
               System.out.println(iterator.next());
        }
        // for loop
        System.out.println("#2 for");
        for (int i = 0; i < lList.size(); i++) {
               System.out.println(lList.get(i));
        }
        // for loop advance
        System.out.println("#3 for advance");
        for (String temp : lList) {
               System.out.println(temp);
        }

        // while loop
        System.out.println("#4 while");
        int j = 0;
        while (j < lList.size()) {
               System.out.println(lList.get(j));
               j++;
        }
    }
}
Output
#1 iterator
Array 1
Array 2
Array 3
#2 for
Array 1
Array 2
Array 3
#3 for advance
Array 1
Array 2
Array 3
#4 while
Array 1
Array 2
Array 3


Wednesday, November 5, 2014

JNDI vs JDBC

JNDI is a protocol / mechanism used to lookup data / information, resources from a SPI that obeys the JNDI format. JNDI is available for manipulating naming services and directory services only. Examples include JNDI trees of EJB Containers, LDAP Directory Servers etc...


JDBC is a database specific protocol that Database vendors support for Java Data Access.


JNDI is used when your are trying to advertise and lookup data from a naming service or directory service and JDBC is used when you are querying / updating data in a Database server.


Difference between JDBC and JNDI

Connection conn = null;
try {
Class.forName ("com.mysql.jdbc.Driver", true, Thread.currentThread (). GetContextClassLoader ());
conn = DriverManager.getConnection ("jdbc: mysql :/ / MyDBServer? user = *** & password = ****");
.....
conn.close ();
}
catch (...) {...} finally {
the if (conn! = null) {
try {
conn.close ();
}
catch (...) {...}
}

Problems?
1, the database server name MyDBServer username and password may need to be modified, and consequent the JDBC URL repairs you want to modify;
2, the database may be the use of other products;
With the increase in the actual terminal, the original configuration of the connection pool parameters may need to be adjusted;

The solution database-level programmers do not have to care about things that only need to know how to refer to
The JNDI appear.
Define the data source, that is, JDBC reference parameters, set a name to the data source;
Data source name in the program by referencing the data source to access the database;

/ Jndi connection
Context initCtx = new InitialContext ();
Context envCtx = (Context) initCtx.lookup ("java: comp / env");
DataSource ds = (DataSource) envCtx.lookup ("jdbc / webtest");
conn = ds.getConnection (); 

/ / Jdbc connection
Class.forName ("com.mysql.jdbc.Driver", true, Thread.currentThread (). GetContextClassLoader ());
conn = DriverManager.getConnection ("jdbc: mysql :/ / localhost / mismain? user = root & autoReconnect = true");

Programmers to develop, you know you want to develop the application to access the MySQL database, so a reference to the MySQL JDBC driver class is encoded by using the appropriate JDBC URL to connect to the database.

Just like the following code:
Connection conn = null;
try ... {
Class.forName ("com.mysql.jdbc.Driver", true, Thread.currentThread (). GetContextClassLoader ());
conn = DriverManager.getConnection ("jdbc: mysql :/ / MyDBServer? user = qingfeng & password = mingyue");
......
conn.close ();
} Catch (Exception e) {
e.printStackTrace ();
} Finally ... {
the if (conn! = null) ... {
try ... {
conn.close ();
} Catch (SQLException e) ... {}
}
}

This is the traditional approach, but also the previously common practice of non-Java programmers (such as Delphi, VB, etc.). This approach generally does not produce in the small-scale development process, as long as the programmers familiar with the Java language, understand the technology and MySQL JDBC can quickly develop the appropriate application.
No JNDI approach the problems: 1, database server name MYDBSERVER, user name and password may need to be changed, which led to the JDBC URL need to be modified; 2, the database may switch to other products, such as switching to DB2 or Oracle, triggered JDBC driver package and class names need to be modified; 3, with the increase of the actual use of the terminal, the original configuration of the connection pool parameters may need to be adjusted; ...

Solution: the programmer should not need to care about what specific database background? JDBC driver? What is JDBC URL format? What is the user name and password to access the database? "And so these problems, programmers write the program should no references to the JDBC driver, server name, user name or password - not even database pool or connection management. But these issues to the J2EE container to configure and manage, the programmer need only reference to these configuration and management.
Thus, there is a JNDI.
JNDI approach: First, configure JNDI parameters, define a data source in a J2EE container, which is the the JDBC reference parameter set a name to the data source; reference data source, the data source name in the program to access the back-end database.
The specific operation is as follows (in JBoss as an example):
1, configure the data source in JBoss D :/ jboss420GA/docs/examples/jca file folder, there are a lot of different databases referenced data source definition template. Copy the mysql-ds.xml file to the server you're using, such as D to :/ jboss420GA/server/default/deploy.
Mysql-ds.xml file to modify the content, so to through JDBC correct access your MySQL database,
As follows:
Connection conn = null;
try ... {
Class.forName ("com.mysql.jdbc.Driver", true, Thread.currentThread (). GetContextClassLoader ());
conn = DriverManager.getConnection ("jdbc: mysql :/ / MyDBServer? user = qingfeng & password = mingyue");
......
conn.close ();
} Catch (Exception e) {
e.printStackTrace ();
} Finally ... {
the if (conn! = null) ... {
try ... {
conn.close ();
} Catch (SQLException e) ... {}
}
}
<? Xml version = "1.0" encoding = "UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name> MySqlDS </ jndi-name>
<connection-url> jdbc: mysql :/ / localhost: 3306/lw </ connection-url>
<driver-class> com.mysql.jdbc.Driver </ driver-class>
<user-name> root </ user-name>
<password> rootpassword </ password>
<exception-sorter-class-name> org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter </ exception-sorter-class-name>
<metadata>
<type-mapping> mySQL </ type-mapping>
</ Metadata>
</ Local-tx-datasource>
</ Datasources>

Defined a the named MySqlDS data source, parameters include the URL of the JDBC driver class name, user name and password.
2 references in the program data source:
Connection conn = null; try ... {
Context ctx = new InitialContext ();
Object datasourceRef = ctx.lookup ("java: MySqlDS"); / / the Citation data source DataSource ds = (DataSource) DataSourceRef; the conn = to the ds.getConnection ();
......
c.close ();
} Catch (Exception e) {
e.printStackTrace ();
} Finally ... {
the if (conn! = null) ... {
try ... {
conn.close ();
} Catch (SQLException e) ... {}
}
}

Using JDBC directly or referenced by JNDI data source programming code is almost the same, but now the program can not care about the specific JDBC parameters.

After the deployment of the system, if the relevant parameters of the database changes, you only need to reconfigure mysql-ds.xml modify the JDBC parameters, as long as the name of the data source is the same, there is no need to modify the source code.

Thus, JNDI to avoid the tight coupling between the program and database to make the application easier to configure, easy to deploy.



Advance Java Blogging

Java New Articles

Javas Latest News

Java Web Services and XML

Ajax Latest News

Mac OS Java Features

Advance Spotlights

Patterns Features