Groovy supports a few neat ways to work with SQL more easily and to make SQL more Groovy. You can perform queries and SQL statements, passing in variables easily with proper handling of statements, connections and exception handling thanks to closures.
import groovy.sql.Sql
def foo = 'cheese'
def sql = Sql.newInstance("jdbc:mysql://localhost:3306/mydb", "user",
"pswd", "com.mysql.jdbc.Driver")
sql.eachRow("select * from FOOD where type=${foo}") {
println "Gromit likes ${it.name}"
}
In the above example, you can refer to the various columns by name, using the property syntax on the row variable (e.g. it.name) or you can refer to the columns by their index (e.g. it[0]) For example:
import groovy.sql.Sql
def foo = 'cheese'
def sql = Sql.newInstance("jdbc:mysql://localhost:3306/mydb", "user",
"pswd", "com.mysql.jdbc.Driver")
def answer = 0
sql.eachRow("select count(*) from FOOD where type=${foo}") { row ->
answer = ro ......
A.ʹÓùؼü×ÖthisµÄ×¼Ôò£º
1.ÔÚ¹¹ÔìÆ÷ÖУ¬Èç¹ûҪʹÓùؼü×Öthis,ÄÇô£¬±ØÐë·ÅÔÚµÚÒ»ÐУ¬·ñÔò½«µ¼ÖÂÒ»¸ö±àÒë´íÎó¡£
2.¹¹Ôì·½·¨ÒýÓÃthisÖ¸ÏòÕýÔÚÖ´Ðз½·¨µÄÀàµÄʵÀý¡£¾²Ì¬·½·¨²»ÄÜʹÓÃthis¹Ø¼ü×Ö£¬ÒòΪ¾²Ì¬·½·¨²»ÊôÓÚÀàµÄʵÀý£¬ËùÒÔthisÒ²¾ÍûÓÐʲô¶«Î÷È¥Ö¸Ïò¡£¹¹ÔìÆ÷µÄthisÖ¸Ïòͬһ¸öÀàÖУ¬²»Í¬²ÎÊýÁбíµÄÁíÍâÒ»¸ö¹¹ÔìÆ÷£¬ÎÒÃÇ¿´¿´ÏÂÃæµÄ´úÂ룺
public class Platypus {
String name;
Platypus(String input) {
name = input;
}
Platypus() {
this("John/Mary Doe");
}
public static void main(String args[]) {
Platypus p1 = new Platypus("digger");
Platypus p2 = new Platypus();
}
}
ÔÚÉÏÃæµÄ´úÂëÖУ¬ÓÐ2¸ö²»Í¬²ÎÊýÁбíµÄ¹¹ÔìÆ÷¡£µÚÒ»¸ö¹¹ÔìÆ÷£¬¸øÀàµÄ³ÉÔ±name¸³Öµ£¬µÚ¶þ¸ö¹¹ÔìÆ÷£¬µ÷ÓõÚÒ»¸ö¹¹ÔìÆ÷£¬¸ø³ÉÔ±±äÁ¿nameÒ»¸ö³õʼֵ "John/Mary Doe".
×¢Ò⣺¾¡¹Ü¿ÉÒÔÓÃthisµ÷ÓÃÒ»¸ö¹¹ÔìÆ÷£¬µ«È´²»Äܵ÷ÓÃÁ½¸ö¡£´ËÍ⣬±ØÐ뽫¹¹ÔìÆ÷µ÷ÓÃÖÃÓÚ×îÆðʼλÖ㬷ñÔò±àÒë»á³ö´í¡£
B.ʹÓÃsupe ......
JavaÈÝÆ÷ÀàѧϰÐĵÃ
ÓÉÓÚÎÒ¶ÔC++±È½ÏÊìϤ£¬ËùÒÔѧϰJavaÓ¦¸ÃÖØµãÌå»áJava´øÀ´µÄиÅÄî¡£±¾ÎÄ»ù±¾ÉÏÊÇJava±ê×¼¿âÖм¯ºÏ¿ò¼ÜµÄ»ù±¾¸ÅÄûÓÐÀý×Ó¡£Ð´±¾ÎĵÄÄ¿µÄÔÚÓÚ·½±ãÎҺܳ¤Ê±¼äºóÈôÊÇÍüÁËÕâЩ¶«Î÷¿ÉÒÔͨ¹ýÕâÆ¬ÎÄÕÂѸËÙ»ØÒäÆðÀ´¡£
1. ½Ó¿Ú
Õû¸öJavaÈÝÆ÷ÀàµÄ»ù´¡ÊÇÈÝÆ÷½Ó¿Ú£¨ÀýÈçCollection£¬MapµÈ½Ó¿Ú£©£¬¶ø²»ÊÇÀࡣʹÓýӿڵÄ×î´óºÃ´¦ÔÚÓÚ½«ÈÝÆ÷µÄʵÏÖÓëÈÝÆ÷µÄ½Ó¿Ú·Ö¿ª£¬Õâ¾ÍÒâζ×ÅÄã¿ÉÒÔʹÓÃÏàͬµÄ·½·¨·ÃÎÊÈÝÆ÷¶ø²»ÓùØÐÄÈÝÆ÷ÊÇÓÉʲôÑùµÄÊý¾Ý½á¹¹ÊµÏֵġ£Í¬Ñù£¬Iterator½Ó¿ÚҲʹµÃÓû§¿ÉÒÔʹÓÃÏàͬµÄ·½·¨·ÃÎʲ»Í¬µÄÈÝÆ÷Àà¡£ÒÔÉÏÕâЩÊÇͨÓÃËã·¨µÄ»ù´¡¡£
1.1 Collection½Ó¿Ú
Collection½Ó¿ÚÓÐÈçÏ»ù±¾·½·¨£º
boolean add(Object obj)£ºÈç¹ûÌí¼Ó¶ÔÏóºó£¬¼¯ºÏȷʵ·¢ÉúÁ˱仯£¬Ôò·µ»Øtrue£»·ñÔò·µ»Øfalse
Iterator iterator()£º·µ»ØÒ»¸öʵÏÖÁËIterator½Ó¿ÚµÄ¶ÔÏó
´ËÍ⣬»¹ÓÐ
int size(),boolean isEmpty()£¬boolean contains(Object obj)£¬void clear()µÈÐí¶àÓÐÓõķ½·¨
1.2 Map½Ó¿Ú
MapÓÃÓÚ´æ·Å¹Ø¼ü×Ö/Öµ¶Ô¡£ÓÐÈçÏ»ù±¾·½·¨£º
Object get(Object key)
Object put(Object key,Object balue)
Set keySet()
Set entrySet()
´ËÍ⣬»¹ÓÐÆäËûÓÐÓõķ ......
£¨1£©³õʼ»¯µÄ˳Ðò£¨¾²Ì¬¡¢·Ç¾²Ì¬¡¢final¡¢±äÁ¿¡¢¶ÔÏó£©
¶ÔÓÚ¾²Ì¬±äÁ¿¡¢¾²Ì¬³õʼ»¯¿é¡¢±äÁ¿¡¢³õʼ»¯¿é¡¢¹¹ÔìÆ÷£¬ËüÃǵijõʼ»¯Ë³ÐòÒÀ´ÎÊÇ£¨¾²Ì¬±äÁ¿¡¢¾²Ì¬³õʼ»¯¿é£©>£¨±äÁ¿¡¢³õʼ»¯¿é£©>¹¹ÔìÆ÷¡£
ÎÒÃÇÒ²¿ÉÒÔͨ¹ýÏÂÃæµÄ²âÊÔ´úÂëÀ´ÑéÖ¤ÕâÒ»µã£º
Java´úÂ룺
public class InitialOrderTest {
// ¾²Ì¬±äÁ¿
public static String staticField = "¾²Ì¬±äÁ¿";
// ±äÁ¿
public String field = "±äÁ¿";
// ¾²Ì¬³õʼ»¯¿é
static {
System.out.println(staticField);
System.out.println("¾²Ì¬³õʼ»¯¿é");
}
// ³õʼ»¯¿é
{
System.out.println(field);
System.out.println("³õʼ»¯¿é");
}
// ¹¹ÔìÆ÷
public InitialOrderTest() {
System.out.println("¹¹ÔìÆ÷");
}
public static void main(String[] args) {
new InitialOrderTest();
}
}
ÔËÐÐÒÔÉÏ´úÂ룬ÎÒÃÇ»áµÃµ½ÈçϵÄÊä³ö½á¹û£º
¾²Ì¬±äÁ¿
¾²Ì¬³õʼ»¯¿é
±äÁ¿
³õʼ»¯¿é
¹¹ÔìÆ÷
£¨2£©³õʼ»¯µÄ˳Ðò£¨×ÓÀà¡¢¸¸Àࣩ
Java´úÂë £º
class Parent {
&nbs ......
ÍÆ¼öÒ»¸ö¾ø¶Ô¾µäµÄÊÓÆµ£¬²»ºÃµÄÄÃשÅÄÎÒ°¡
ÎÞÒâÖÐÔÚÍøÉÏÏÂÔØµ½Ò»Ì×ÊÓÆµ£¬ÒѾȫ³ÌÌýÍ꣬¸Ð¾õ·Ç³£²»´í¡£´ÓJava»ù´¡¿ªÊ¼ÑÐò½¥½ø£¬ÓÉdzÈëÉÊÓÆµÖв»½ö¾«
±ÙµÄ½²½âÁËJava¿ª·¢µÄ֪ʶ£¬¶øÇÒÈÚÈëÁ˺ܶàѧϰ·½·¨µÄ½²½âºÍ±à³Ì˼ÏëµÄÒýµ¼£¬×ÛºÏÀ´Ëµ¿ÉÒÔÈË¿°³ÆÈëÃŵľµäÖ®
×÷!
ÌØ±ðÍÆ¼ö¸ø´ó¼Ò£¬´ó¼Ò¹²Í¬½ø²½¡£°ÑÍøÖ·¸ø´ó¼Ò·¢¹ýÈ¥£¬´ó¼Ò¿ÉÒÔÈ¥ÏÂÔØ http://javass.qupan.com/ ......
±¾ÔÂ3ÈÕSunµÄJ2SE 5.0ʵÏÖÒÑÖÕ½á·þÎñÖÜÆÚ£¨End of Service Life£¬¼´EOSL£©£¬ÕâÒ»ÌìÒ²ÊÇ×îºóµÄÒ»´Î5.0¸üз¢²¼ÈÕÆÚ£¨J2SE 5.0 Update 22£©¡£Ñ°ÇóSunÖ§³ÖµÄÓû§¿ÉÒÔÑ¡ÔñÉý¼¶µ½Java 6»òÊǶ©ÔÄSunµÄJava for Business³ÌÐò¡£
SunÌṩÁ˶àÖÖ¶àÑùµÄJava¸¶·ÑÖ§³Ö¡£Java¾µäÖ§³Ö£¨classic support£©º¸ÇÁË´Ó²úÆ··¢²¼Ö®ÈÕÆð3ÄêÄÚµÄÖ§³Ö£¬Ëü·ÖΪÁ½Àࣺ±ê×¼Ö§³ÖºÍ¸ß¼¶Ö§³Ö¡£±ê×¼Ö§³ÖÌṩÁ˹¤×÷ʱ¼ä12x5µÄ¸²¸ÇÃæÓë4¸öСʱµÄÏìӦʱ¼äSLA£¬¸ß¼¶Ö§³ÖÌṩÁË24x7µÄ¸²¸ÇÃæÓ뼴ʱÏìÓ¦¡£Java¾µäÖ§³ÖµÄ·ÑÓÃΪÿÄê$15,000Æð£¬Ëæ×Å×éÖ¯¹æÄ£µÄÔö¼Ó·ÑÓÃÒ²ËæÖ®ÉÏÉý£¬¶ÔÓÚ³¬´óÐÍÆóÒµ·ÑÓÿÉÒԴﵽÿÄê$250,000¡£
À©Õ¹Ö§³ÖÊÇÕë¶ÔÄÇЩ´ïµ½EOSLµÄJava°æ±¾À´ËµµÄ£¬Óû§¿ÉÒÔͨ¹ýSunµÄJava for Business³ÌÐò»ñµÃ¸ÃÖ§³Ö£¬Ö§³Öº¸ÇÁËJava 1.4.2¡¢5¼°6°æ±¾¡£Java for BusinessºÏͬ½«JavaÖ§³ÖÀ©Õ¹µ½ÁË15Ä꣬ÕâÒâζ×ÅJava 1.4.2Ö§³Ö½«Ò»Ö±³ÖÐøµ½2017Äê¡£ÔÚÀ©Õ¹Ö§³ÖÆÚ¼ä£¬Sun»á¼ÌÐøÌṩ°²È«²¹¶¡Óë¸üÐÂÒÔÖ§³Öаæ²Ù×÷ϵͳ¡£Java for Business¾ßÓÐÈçÏÂËÄÖÖÇéÐΣº
Ö»¶Á·ÃÎÊ¡£Ã¿¼¾¶ÈÓû§¿ÉÒÔÏÂÔØ°²È«²¹¶¡¡¢bugÐÞ¸´¼°Ð²Ù×÷ϵͳ֧³Ö°æ±¾¡£ÕâЩÏÂÔØÏî¶¼ÊǶþ½øÖÆÐÎʽµÄ£¬Óû§ÐèÒª´ÓSunÕ¾µãÏÂÔØ¡£Ëü²¢²»ÌṩÈκεİïÖú ......