Java Application Ö±½Óͨ¹ýjndiÁ¬½ÓÊý¾Ý¿â
À´Ô´£ºhttp://www.ej38.com/showinfo/java-132636.html
ʹÓÃjar°ü:
commons-pool-1.5.3.jar,tomcat-naming-common.jar,commons-pool-1.5.3-bin.zip,commons-dbcp.jar
×¢Òâ:jdbc Çý¶¯ÒªÓëÊý¾Ý¿â¼æÈÝ.
package test.comm;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Hashtable;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource;
public class DBConnector {
static private InitialContext ic = null;
static private DataSource ds = null;
static private void initContext(){
try {
BasicDataSource bds = new BasicDataSource();
bds.setUrl("jdbc:oracle:thin:@localhost:1521:test");
bds.setDriverClassName("oracle.jdbc.OracleDriver");
bds.setUsername("test");
bds.setPassword("a");
Hashtable<String, String> evn = new Hashtable<String,String>();
evn.put("java.naming.factory.initial","org.apache.naming.java.javaURLContextFactory");
ic = new InitialContext(evn);
ic.bind("mydatasource", bds);
ds = (DataSource) ic.lookup("mydatasource");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
static public Connection getConn() throws SQLException{
if (ds == null){
initContext();
}
return ds.getConnection();
}
}
²âÊÔ:
package test;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import test.comm.DBConnector;
public class wfTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Connection conn = DBConnector.getConn();
System.out.println("conn = "+conn);
String qSQL = "SELECT USERNAME,LOGINID from S_U_USER";
Statement stmt = conn.createStatement();
Ïà¹ØÎĵµ£º
1.ÕýÔò±í´ïʽ½á¹¹¼ò½é£º
С֪ʶ£º{}¡¡¶¨ÒåÁËÒ»¸ö·¶Î§¡¡ [] ¶¨ÒåÁËÒ»¸ö×Ö·ûÀà¡¡() ¶¨ÒåÁËÒ»¸ö×é
*Ç°Ãæ³öÏÖ0´ÎÒÔÉÏ +¡¡Ç°ÃæÆ¥ÅäÒ»´ÎÒÔÉÏ¡¡?Ç°Ãæ³öÏÖ0´Î»òÒ»´Î
1).×Ö·û£º
x------×Ö·ûx
\\-----·´Ð±¸Ü
\0n----Ê®½øÖÆÊý (0 <= n <= 7)
\0nn---Ê®½øÖÆÊý0nn (0 <= n <= 7)
\0mnn--Ê®½øÖÆÊý ......
Ê×ÏÈboolean²»ÄܸúÆäËûÀàÐÍת»»¡£
1.¸³ÖµÊ±£º
ÕûÊýĬÈϵÄÊÇint ¸¡µãĬÈÏÊÇdouble£¬¼´ÕûÐ͵ȺÅÓÒ²àÈ«²¿×Ô¶¯×ª»¯Îªint£¬¸¡µãÐ͵ȺÅÓÒ²à×Ô¶¯×ª»»Îªdouble¡£µ±´óÈÝÁ¿µÄÊý¾ÝÀàÐ͸³Öµ¸øСÈÝÁ¿µÄÊý¾ÝÀàÐÍʱ ÐèҪǿÖÆÀàÐÍת»»µ«ÊÇÓÐ ......
1. ¸ÅÊö
±¾ÎÄÖ÷Òª°üÀ¨ÒÔϼ¸¸ö·½Ã棺±àÂë»ù±¾ÖªÊ¶£¬java£¬ÏµÍ³Èí¼þ£¬url£¬¹¤¾ßÈí¼þµÈ¡£
ÔÚÏÂÃæµÄÃèÊöÖУ¬½«ÒÔ"ÖÐÎÄ"Á½¸ö×ÖΪÀý£¬¾²é±í¿ÉÒÔÖªµÀÆäGB2312±àÂëÊÇ"d6d0 cec4"£¬Unicode±àÂëΪ"4e2d 6587"£¬UTF±àÂë¾ÍÊÇ"e4b8ad e69687"¡£×¢Ò⣬ÕâÁ½¸ö×ÖûÓÐiso8859-1±àÂ룬µ«¿ÉÒÔÓÃiso8859-1±àÂëÀ´"±íʾ"¡£
2. ±àÂë»ù±¾ÖªÊ ......
¼ÆËãijһÔ·ݵÄ×î´óÌìÊý
Calendar time=Calendar.getInstance();
time.clear();
time.set(Calendar.YEAR,year); //year Ϊ int
time.set(Calendar.MONTH,i-1);//×¢Òâ,Calendar¶ÔÏóĬÈÏÒ»ÔÂΪ0
int day=time.getActualMaximum(Calendar.DAY_OF_MONTH);/ ......
×Ô´ÓѧϰJavaÒÔÀ´ÒѾһÄêÓÐÓàÁË£¬¶ÔJava»¹Ö»Êdzõ½×¶ÎµÄÁ˽⣬¶¼¹ÖÔÚѧУµÄʱºòÌ°ÍæûÓÐÓÐЧµÄÀûÓÃʱ¼ä£¬ÏÖÔÚÔÚÒ»¸öÅàѵѧУѧϰJava£¬ÏÖÔÚ¾ÍÒª×öÏîÄ¿ÁË»¹ÊÇʲô¶¼²»¶®£¬»¹ºÃÓÐCsdn¡£
ÔÚCsdnµÄÈÕ×ÓÀï½ÐÎÒÕÒµ½Á˼ҵĸоõ£¬µÃµ½Á輆 ......