連結mysql
try


{
??Class.forName("org.gjt.mm.mysql.Driver").newInstance();

}
catch(Exception?e1)


{
??out.print("11111111111111111111"+e1.getMessage());
}
try


{
???String?url="jdbc:mysql://localhost/test";
??java.sql.Connection?cn=java.sql.DriverManager.getConnection(url,"root","wujun");
?//?Connection?cn?=?DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=wujun&useUnicode=true&characterEncoding=8859_1");
??java.sql.Statement?sm=cn.createStatement();
??String?strsql="select?*?from?table1";
??java.sql.ResultSet?rs=sm.executeQuery(strsql);
??while(rs.next())

??
{
????out.print(rs.getInt(1)+":");
????out.print(rs.getString(2));
????out.print("********************<br>");
??}
??//rs.close();
??sm.close();
??cn.close();
}

catch(Exception?ee)


{
??out.print(ee.getMessage());
}#########################################################################
Properties 文件操作
?java.util.Properties?prp=new?Properties();
????java.io.FileInputStream?ipt=new?FileInputStream("c:/1.properties");
????prp.load(ipt);
????java.util.Enumeration?en=prp.keys();
????while(en.hasMoreElements())

????
{
??????out.print(en.nextElement());
??????//out.print(prp.get(en.nextElement()));
????}
????//prp.put("name","wujunjun");
????//prp.put("name1","aaaaa");
???//?prp.put("name2","bbbbb");
???//?prp.put("name3","ccccc");
???//?prp.put("name4","dddddd");
??//??try
??//??{

?????//?java.io.FileOutputStream?fot=new?FileOutputStream("c:/1.properties");
????//??prp.store(fot,"first?in?properties");

????//}
???//?catch(Exception?ee)
???//?{
????//??out.print(ee.getMessage());
???//?}#########################################################################
日志測試
package?logtest.test;

import?org.apache.log4j.*;

import?java.io.*;

public?class?Test?
{
????private?Logger?log=Logger.getLogger(this.getClass());

????public?Test()?
{
????}
????public?void?add()

????
{
???????try

???????
{
???????????int?i=0;
???????????File?f=new?File("c:\\a.txt");
???????????java.io.FileReader?fr=new?FileReader(f);
???????????fr.toString();
??????????this.del();
???????}

???????catch(Exception?ee)
{
???????????log.fatal("fatal:"+ee);
???????????log.error("error:"+ee);
???????????log.warn("warn"+ee);
???????????log.info("OK,error?begin");
???????????log.debug("debug:"+ee);
???????}
????}
????public?void?del()

????????????
{
????????????????new?Exception("djkflsjkfsjdklfjsdlkflsdjkjk");
????????????}

????public?static?void?main(String[]?args)?
{
????????Test?test?=?new?Test();
????????test.add();
????}
}
class目錄下
log4j.properties
log4j.rootLogger=fatal,console,file
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=log.txt

log4j.appender.console.layout=org.apache.log4j.SimpleLayout
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%t?%p?-?%m%n?%C########################################################################
集合hashTable
#####################################################################
package?hashTable;

import?java.util.*;

public?class?hashTable


{
????
????public?static?void?main(String?args[])

????
{
????????try

????????
{
????????
????????java.util.Hashtable?hs=new?Hashtable();
????????
????????for(int?i=0;i<10;i++)

????????
{
????????????hs.put(i,i+"a");
????????}
????????
????????Enumeration?e2=hs.keys();
????????System.out.println("key:");
????????while(e2.hasMoreElements())

????????
{
????????????
????????????//System.out.print(e2.nextElement()+"value:");
????????????System.out.println(hs.get(e2.nextElement()));
????????}
????????java.util.Enumeration?ee=hs.elements();
????????System.out.println("value:");
????????while(ee.hasMoreElements())

????????
{
????????????System.out.println(ee.nextElement());
????????}
????????}
????????catch(Exception?e)

????????
{
????????????System.out.println(e.getMessage());
????????}
????}
}

#######################################################################
集合Vector
########################################################################
package?vector;

import?java.util.*;


public??class?MyVector?extends?Vector


{
????public?void?addInt(int?i)

????
{
????????addElement(new?Integer(i));????
????}
????public?void?addFloat(Float?f)

????
{
????????addElement(new?Float(f));
????}
????public?void?addString(String?str)

????
{
????????addElement(str);
????}
????public?void?addCharArray(char?a[])

????
{
????????addElement(a);
????}
????public?void?printVector()

????
{
????????Object?o;
????????int?lenght=size();
????????System.out.println("向量元素數為:"+lenght+";他們是:");
????????for(int?i=0;0<lenght;i++)

????????
{
????????????o=elementAt(i);
????????????if(o?instanceof?char[])

????????????
{
????????????????System.out.println(String.copyValueOf((char[])o));
????????????}
????????????else

????????????
{
????????????????System.out.println(o.toString());
????????????}
????????}
????????
????}
????
????public?static?void?main(String?args[])

????
{
????????MyVector?v=new?MyVector();
????????int?digit=5;
????????float?feal=3.14f;

????????char?letters[]=
{'a','b','c','f','d'
????????};
????????String?s=new?String("挖,你在那里");
????????v.addInt(digit);
????????v.addFloat(feal);
????????v.addString(s);
????????v.addCharArray(letters);
????????v.printVector();
????????
????}
????????
}

#######################################################################
???????????????????????? 轉載請注名出處:http://www.tkk7.com/wujun
#######################################################################
VectorExcample
package?vector;

import?java.util.*;

public?class?VectorExcample


{
????public?static?void?main(String??agrs[])

????
{
????????Vector?v=new?Vector(3,2);
????????System.out.println("大小"+v.size());
????????System.out.println("容量"+v.capacity());
????????v.addElement(new?Integer(2));
????????v.addElement(new?Integer(3));
????????v.addElement(new?Integer(7));
????????v.addElement(new?Integer(5));
????????System.out.println("當前容量:"+v.capacity());
????????v.addElement(new?Double(10.04));
????????v.addElement(new?Float(11.4));
????????System.out.println("當前容量:"+v.capacity());
????????if(v.contains(new?Integer(2)))

????????
{
????????????System.out.println("向量包括2");
????????????}
????????java.util.Enumeration?ee=v.elements();
????????while(ee.hasMoreElements())

????????
{
????????????System.out.println(ee.nextElement()+"");
????????????}
????????????System.out.println();
????????}
????}
StackExample
package?vector;

import?java.util.*;

public?class?StackExample


{
????public?static?void?main(String?args[])

????
{
????????Stack?s=new?Stack();
????????System.out.println("大小:"+s.size());
????????System.out.println("容量:"+s.capacity());
????????s.push(new?Integer(2));
????????s.push(new?Integer(4));
????????s.push(new?Integer(6));
????????s.push(new?Integer(8));
????????System.out.println("當前容量:"+s.capacity());
????????s.push(new?Double(10.04));
????????s.push(new?Float(11.4));
????????System.out.println("當前容量"+s.capacity());
????????if(s.contains(new?Integer(2)))

????????
{
????????????System.out.println("棧中包含2");
????????}
????????while(!s.empty())

????????
{
????????????System.out.println(s.pop());????
????????}
????}
}

JDBC執行sqlserver存儲過程,帶輸出參數
package?dbObject;

import?java.sql.*;

public?class?linkDB


{
????public?static?void?main(String?args[])

????
{
????????try

????????
{
????????
????????????Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
????????????Connection?con=java.sql.DriverManager.getConnection("jdbc:odbc:blogdb","sa","");
????????????java.sql.CallableStatement?ca=con.prepareCall("{call?gettongji(?,?,?,?)}");
????????????ca.registerOutParameter(1,java.sql.Types.INTEGER);
????????????ca.registerOutParameter(2,java.sql.Types.INTEGER);
????????????ca.registerOutParameter(3,java.sql.Types.INTEGER);
????????????ca.registerOutParameter(4,java.sql.Types.INTEGER);
????????????ca.execute();
????????????System.out.println(ca.getInt(1));
????????????System.out.println(ca.getInt(2));
????????????System.out.println(ca.getInt(3));
????????????System.out.println(ca.getInt(4));
????????????
????????//????java.sql.Statement?stet=con.createStatement();
????????//????String?sql="insert?into?table1(address,age,sex)?values('江西南昌',22,'男')";
????????///????stet.executeUpdate(sql);
????????//????PreparedStatement?pstet=con.prepareStatement("insert?into?table1?values(?,?,?)");
????????//????pstet.addBatch();
????????//????pstet.setString(1,"北京");
????????//????pstet.setInt(2,80);
????//????????pstet.setString(3,"女");
????//????????pstet.executeUpdate();
????????//????stet.close();
????????ca.close();
????????????con.close();
????????????
????????}
????????catch(Exception?ee)

????????
{
????????????System.out.println(ee.getMessage());
????????}
????????
????}
????
}?##################################################
???今天就到這吧。。有空再整理。。
轉載請注明:http://www.tkk7.com/wujun/