reference:
http://ant.apache.org/manual/
1. 新建c:\javademo目錄
2. 在javademo目錄下,新建src\oata\文件夾
3.在oata目錄下新建文件
package oata;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
4.在javademo目錄下:
md build\classes
javac -sourcepath src -d build\classes src\oata\HelloWorld.java
java -cp build\classes oata.HelloWorld
可以看到結果:
Hello World
5.在javademo目錄下:
echo Main-Class: oata.HelloWorld>myManifest
md build\jar
jar cfm build\jar\HelloWorld.jar myManifest -C build\classes .
java -jar build\jar\HelloWorld.jar
也可以看到結果:
Hello World
posted @
2008-12-04 11:29 張辰 閱讀(128) |
評論 (0) |
編輯 收藏
1. 去c:新建一個目錄 javademo (md javademo)
2.在目錄下新建一個文件 : HelloWorldApp.java
class HelloWorldApp
{
public static void main(Stirng[] args)
{
System.out.println("Hello World!");
}
}
3. 保存后,在當前目錄下面運行:javac HelloWorldApp.java
4.運行 java HelloWorldApp
posted @
2008-12-04 11:05 張辰 閱讀(113) |
評論 (0) |
編輯 收藏
reference:
http://dev.yesky.com/275/2132275.shtml
1.在eclipse新建一個java project
2.新建一個class: hello, package = example, 代碼如下:
package example;
public class hello
{
public int abs(int n)
{
return n >= 0 ? n : (-n);
}
}
3.右鍵點擊hello.java,選擇:new - junit test case
setUp / tearDown打鉤, 最下方click here點擊,添加JUnit.jar文件 - next
4.選擇abs()方法
5.修改Hellotest代碼:
package example;
import junit.framework.TestCase;
public class helloTest extends TestCase
{
private hello _hello;
protected void setUp() throws Exception
{
super.setUp();
_hello = new hello();
}
protected void tearDown() throws Exception
{
super.tearDown();
}
public void testAbs()
{
assertEquals(_hello.abs(14), 14);
assertEquals(_hello.abs(-5), 5);
assertEquals(_hello.abs(0), 0);
}
}
6. 運行
posted @
2008-12-03 15:38 張辰 閱讀(132) |
評論 (0) |
編輯 收藏
Oops! Eclipse + JSP + Applet + JMF Quick Start
Reference:
http://community.csdn.net/Expert/topic/5481/5481629.xml?temp=.1175043
applet的class文件最好不要放在web-inf目錄下,因為這是個特殊目錄
視頻測試文件:
/Files/pixysoft/test.rar
Quick Start:
新建一個Dynamic Web Project項目,叫做Oops_JMF_Applet,然后修改project – properties,default output folder為:Oops_JMF_Applet/WebContent/classes

添加以下引用,全部可以在JMF包里面找到

在src目錄下面增加一個文件:PlayerApplet.java
import java.applet.*;
import java.awt.*;
import java.net.*;
import javax.media.*;
public class PlayerApplet extends Applet implements ControllerListener
{
Player player = null;
public void init()
{
setLayout(new BorderLayout());
String mediaFile = getParameter("FILE");
try
{
URL mediaURL = new URL(getDocumentBase(), mediaFile);
player = Manager.createPlayer(mediaURL);
player.addControllerListener(this);
}
catch (Exception e)
{
System.err.println("Got exception " + e);
}
}
public void start()
{
player.start();
}
public void stop()
{
player.stop();
player.deallocate();
}
public void destroy()
{
player.close();
}
public synchronized void controllerUpdate(ControllerEvent event)
{
if (event instanceof RealizeCompleteEvent)
{
Component comp;
if ((comp = player.getVisualComponent()) != null)
add("Center", comp);
if ((comp = player.getControlPanelComponent()) != null)
add("South", comp);
validate();
}
}
}
在WebContent下面添加一個文件index.jsp。注意codebase問題
<html>
<body>
<APPLET CODE=PlayerApplet WIDTH=320 HEIGHT=300
codebase="/Oops_JMF_Applet/classes/">
<PARAM NAME=FILE VALUE="test.mpg">
</APPLET>
</body>
</html>
程序clean一下,在webContent目錄下面添加一個test.mpg文件,然后選擇index.jsp,Run on Server,選一個tomcat服務器,ok!

可惜不能截圖。。。
posted @
2007-09-15 01:24 張辰 閱讀(1100) |
評論 (0) |
編輯 收藏
Oops! Bea Sip Server Quick Start Part 2
Purpose
掌握由網頁發出sip的invite請求。
Precondition:
http://www.tkk7.com/pixysoft/archive/2007/09/11/144131.html
Quick Start
在上一章,掌握了安裝sip server,kapanga,然后寫了一個注冊的機制。這張寫一個網頁觸發invite的事件,呼叫客戶端。
首先建一個dynamic web project,叫做Oops_Sip_02,然后修改WebContent,改為invite,修改properties,把Default output folder改為:Oops_Sip_02/invite/WEB-INF/classes,刪除build目錄,最后整個項目為:

修改.classpath文件,增加3個引用:注意這3個引用是你安裝目錄下的。
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk150_06"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="lib" path="C:/bea/sipserver30/server/lib/wlss/wlss.jar"/>
<classpathentry kind="lib" path="C:/bea/sipserver30/server/lib/wlss/sipservlet.jar" sourcepath="C:/bea/sipserver30/server/lib/wlss/sipservlet.jar"/>
<classpathentry kind="lib" path="C:/bea/sipserver30/server/lib/weblogic.jar"/>
<classpathentry kind="output" path="invite/WEB-INF/classes"/>
</classpath>
在src目錄下面增加2個文件
httpControlServlet
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class httpControlServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doAction(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
doAction(request, response);
}
private void doAction(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
String sip = request.getParameter("sip");
sipControlServlet.DoConnection(sip);
RequestDispatcher rds;
rds = getServletContext().getRequestDispatcher("/index.jsp");
rds.forward(request, response);
return;
}
}
sipControlServlet
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.sip.*;
import com.bea.wcp.sip.util.TransportUtil;
public class sipControlServlet extends SipServlet
{
private static Address myAddress;
private static SipFactory factory;
public void init(ServletConfig cfg) throws ServletException
{
super.init(cfg);
factory = (SipFactory) getServletContext().getAttribute(
SipServlet.SIP_FACTORY);
String uri = "sip:oops@localhost:5062";
myAddress = factory.createAddress(uri);
System.out.println("Oops! Sip Server Demo 2");
}
public static void DoConnection(String sip) throws ServletException,
IOException
{
SipApplicationSession appSession = factory.createApplicationSession();
Address to = factory.createAddress("sip:" + sip);
SipServletRequest invite = factory.createRequest(appSession, "INVITE",
myAddress, to);
invite.send();
System.out.println("Connection successful!");
}
protected void doResponse(SipServletResponse resp) throws ServletException,
IOException
{
resp.createAck().send();
}
}
在invite/WEB-INF下面建2個文件:
sip.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sip-app
PUBLIC "-//Java Community Process//DTD SIP Application 1.0//EN"
"http://www.jcp.org/dtd/sip-app_1_0.dtd">
<sip-app>
<display-name>Oops Sip Server Quick Start 2</display-name>
<distributable />
<servlet>
<servlet-name>sipControlServlet</servlet-name>
<servlet-class>sipControlServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- system user for the run-as element for Registrar -->
<security-role>
<role-name>system-user</role-name>
</security-role>
</sip-app>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>testsender</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>httpControlServlet</servlet-name>
<servlet-class>httpControlServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>httpControlServlet</servlet-name>
<url-pattern>/http.oops</url-pattern>
</servlet-mapping>
</web-app>
在invite目錄下添加index.jsp
<html>
<body>
<form name="form_sip" action="http.oops"
method="post"><input name="sip" value="user1@192.168.0.130:5061"
type="text" style="width: 240px"><input type="submit"></form>
</body>
</html>
最后整個目錄變為:

大概解說一下:用戶網頁輸入sip,傳遞給后臺httpservlet,其調用sipservlet的靜態方法,創建一個會話到用戶。
現在吧項目部署在bea sip server上面,方法參考前面的文章。然后在瀏覽器輸入:
http://localhost:7001/invite

之后打開kapanga,在點擊網頁

完成!
posted @
2007-09-13 08:18 張辰 閱讀(777) |
評論 (1) |
編輯 收藏
Oops! Bea Sip Server Quick Start Part 1
Purpose
掌握bea sip server 3.0
就是bea公司推出的一個sip的服務器,適合下一代電信網絡。
首先聲明一下,這個quick start比較有難度,我調了1個多小時才出來。很多很無聊的細節要注意!
Precondition:
sipserver300_win32.exe 328 MB (這個有點難度,可能需要去bea主頁下載,還要申請)
kapanga 一個sip電話:http://www.kapanga.net/ip/download.cfm
Quick Start
Bea Sip Server 安裝
首先當然是安裝sipserver 3.0。很簡單,根據提示沒有問題,不過要注意,不要使用中文文件夾、不要過長的文件夾。
然后在sip server里面建立一個自己的domain,也很簡單,不過要注意,要使用java jdk 1.5,不要使用其他的,否則有問題。然后在ie輸入:
http://localhost:7001/console
就可以看到登錄框!輸入用戶名和密碼就可以進入:

Kapanga sip 電話安裝
然后安裝kapanga,需要配置,如圖:

Username: user1
Display name: user1
Default URL: user1@192.168.0.130
注意,這個ip在運行 – cmd – ipconfig看到


Domain/realm: 192.168.0.130
sip proxy: 192.168.0.130:5060
outbound proxy: 192.168.0.130:5060
選擇register

Local udp sip port: 5061

Eclipse 開發
然后關掉Kapanga,打開eclipse,新建一個項目Dynamic web project叫做Oops_Sip_01。注意以下設置:

然后確認之后生成項目目錄。選擇 project – properties – java build path – source,把default output folder修改為Oops_Sip_01/web/WEB-INF/classes。

確認后刪除掉build目錄,可以看到如下的結構

打開.classpath文件,修改如下,即引用了3個類,來自bea的sipserver,這個看大家的安裝目錄確定。
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src" />
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_02" />
<classpathentry kind="con"
path="org.eclipse.jst.j2ee.internal.web.container" />
<classpathentry kind="lib"
path="C:/bea/sipserver30/server/lib/wlss/wlss.jar" />
<classpathentry kind="lib"
path="C:/bea/sipserver30/server/lib/wlss/sipservlet.jar"
sourcepath="C:/bea/sipserver30/server/lib/wlss/sipservlet.jar" />
<classpathentry kind="lib"
path="C:/bea/sipserver30/server/lib/weblogic.jar" />
<classpathentry kind="output" path="web/WEB-INF/classes" />
</classpath>
在web " WEB-INF " lib目錄下面添加以下jar文件,這些文件都可以在eclipse / plugin 里面和下載了jstl.jar文件包里面找到。沒有的問我。

在web " WEB-INF"下添加文件夾tlds,添加以下文件:

在src目錄下面添加3個java文件:
DisplayURIServlet 這里getRequestDispatcher("/index.jsp");很關鍵!
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class DisplayURIServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
HttpSession session = request.getSession();
session.setAttribute("user", UserController.Instance().GetList());
response.setContentType("text/html; charset=gb2312");
RequestDispatcher rds;
rds = getServletContext().getRequestDispatcher("/index.jsp");
rds.forward(request, response);
return;
}
}
Registration
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.sip.*;
public final class Registration extends SipServlet
{
public void init(ServletConfig sc) throws ServletException
{
super.init(sc);
System.out.println("Oops! First Sip Application!");
}
// 把用戶保存起來
public void doRegister(SipServletRequest req) throws IOException,
ServletParseException
{
UserController.Instance().AddUser((SipURI) req.getTo().getURI());
SipServletResponse res = req.createResponse(200);
res.send();
}
}
UserController
import java.util.ArrayList;
import java.util.List;
import javax.servlet.sip.*;
public class UserController
{
List<SipURI> userList = new ArrayList<SipURI>();
private static UserController instance;
public static UserController Instance()
{
if (instance == null)
instance = new UserController();
return instance;
}
public void AddUser(SipURI url)
{
if (userList.contains(url))
return;
userList.add(url);
}
public List<SipURI> GetList()
{
return userList;
}
}
在web下面添加index.jsp文件
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<body>
<c:choose>
<c:when test="${empty sessionScope.user}">
Oops!No user!</c:when>
<c:otherwise>
<c:out value="${user}"/>
</c:otherwise>
</c:choose>
</body>
</html>
修改web/WEB-INF目錄下的web.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>caonima</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tlds/c.tld</taglib-location>
</taglib>
</jsp-config>
<servlet>
<servlet-name>user</servlet-name>
<servlet-class>
DisplayURIServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>user</servlet-name>
<url-pattern>/sip.oops</url-pattern>
</servlet-mapping>
</web-app>
在web/WEB-INF/目錄下面添加2個xml文件:
sip.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sip-app
PUBLIC "-//Java Community Process//DTD SIP Application 1.0//EN"
"http://www.jcp.org/dtd/sip-app_1_0.dtd">
<sip-app>
<display-name>Oops! First SIP Servlet</display-name>
<distributable/>
<servlet>
<servlet-name>registrar</servlet-name>
<servlet-class>Registration</servlet-class>
<load-on-startup>1</load-on-startup>
<!-- system user -->
<run-as>
<role-name>system-user</role-name>
</run-as>
</servlet>
<servlet-mapping>
<servlet-name>registrar</servlet-name>
<pattern>
<equal>
<var>request.method</var>
<value>REGISTER</value>
</equal>
</pattern>
</servlet-mapping>
<!-- system user for the run-as element for Registrar -->
<security-role>
<role-name>system-user</role-name>
</security-role>
</sip-app>
weblogic.xml
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<weblogic-web-app
xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
<run-as-role-assignment>
<role-name>system-user</role-name>
<run-as-principal-name>weblogic</run-as-principal-name>
</run-as-role-assignment>
</weblogic-web-app>
Ok!!完成了項目開發。整體目錄如下:

選擇project – clean命令編譯項目

Sip Server部署
現在啟動sip server,然后進入deployment頁面:

點擊lock & edit,然后可以點擊install,來到你的項目位置,選擇之后一直next到finish

激活你的部署:

同時在sip的Console可以看到一條語句:

然后選擇你的項目,Start – serving all request,然后確定就好了!

打開ie,輸入:http://localhost:7001/web/index.jsp,可以看到:

現在運行Kapanga,一定要注意設置,按照上面的設置:

然后再回到ie,輸入:http://localhost:7001/web/sip.oops,可以看到:

一項艱巨的quick start完成!
posted @
2007-09-11 02:12 張辰 閱讀(840) |
評論 (0) |
編輯 收藏
Oops! JMF Video Cam Quick Start(Java攝像頭抓取)
Reference:
Oops! JMF Quick Start
http://www.tkk7.com/pixysoft/archive/2007/09/07/143408.html
JMF應用篇 之 從攝像頭捕獲視頻
http://blog.csdn.net/sunny3106/archive/2007/05/06/1598143.aspx
Quick Start
安裝jmf-2_1_1e-windows-i586.exe,可以在我的第一個JMF教程里面下載。然后運行JMF Registry,選擇Capture Devices里面的Detect capture Devices,得到以下結果:

eclipse里面新建一個Java Project,名字叫做Oops_JMFCam。項目添加引用jmf.jar,在安裝目錄下面的lib找到。

在項目的src目錄下面添加文件CaptureVideo.java。
import javax.media.*;
import java.io.*;
import java.awt.*;
classCaptureVideoextendsFrameimplementsControllerListener
{
privateCaptureDeviceInfo infor;
privateMediaLocator mediaLocator;
privateString url = "vfw:Microsoft WDM Image Capture (Win32):0";
privateComponent com;
privatePanel panel;
Player player;
public CaptureVideo()
{
infor = CaptureDeviceManager.getDevice(url);
mediaLocator = infor.getLocator();
}
publicvoid play()
{
try
{
player = Manager.createPlayer(mediaLocator);// 利用mediaLocator創建Player
player.addControllerListener(this);
player.realize();
// System.out.println("infor:"+infor);
// System.out.println("mediaLocator:"+mediaLocator);
}
catch (NoPlayerException e)
{
// TODO 自動生成 catch 塊
e.printStackTrace();
}
catch (IOException e)
{
// TODO 自動生成 catch 塊
e.printStackTrace();
}
}
publicvoid createComponent()
{
setTitle("視頻信號");
// addWindowListener(new WinClose());
setBounds(100, 100, 200, 200);
panel = newPanel();
if ((com = player.getVisualComponent()) != null)
{
panel.add(com);
}
add(panel);
setVisible(true);
}
publicsynchronizedvoid controllerUpdate(ControllerEvent arg0)
{
// TODO 自動生成方法存根
if (arg0 instanceofRealizeCompleteEvent)
{
System.out.println("realized");
createComponent(); // 將播放器添加到Panel上
player.prefetch();
}
if (arg0 instanceofPrefetchCompleteEvent)
{
player.start();
System.out.println("prefetched");
}
}
publicstaticvoid main(String[] arg0)
{
CaptureVideo video = newCaptureVideo();
video.play();
}
}
Run as Java Application,得到結果

posted @
2007-09-09 23:52 張辰 閱讀(1630) |
評論 (0) |
編輯 收藏
不要看什么TestDriven之類的大道理。。
那些人為了提升一個小小的idea,于是寫出了一大堆的廢話來忽悠。就像xxx領導的yyy理論一樣。
我們程序員需要的是實際。
其實,測試驅動的精髓在于:
不啟動整個大型項目能夠對某個小方法進行運行調試。
比如我在寫一個大型網站,現在要測試數據庫的調用之類的,但是我不能每次調試都啟動整個網站,時間太長了,怎么辦?
1.首先當然要實現了這個數據庫調用類。
2.專門寫一個testme.java文件,里面初始化這個類,傳入參數,然后看結果
3.這個testme.java文件可以遵循JUnit之類的要求。
這樣不用在整個項目里面添加一大堆測試類就能夠測試了。而且testme.java文件是個臨時文件,當測試通過直接就刪了。
小結:
我們寫程序為了驗證某個方法是否可行,經常需要寫個小程序去測試,這就是測試驅動。
posted @
2007-09-09 10:22 張辰 閱讀(244) |
評論 (0) |
編輯 收藏
Oops! Access Ole Object Quick Start
Purpose:
操作accress的ole對象。并掌握測試驅動
Quick Start
新建一個名叫Oops_Access的項目java project。新建一個lib文件夾,導入以下類庫
添加項目依賴性


在項目根目錄加入一個demo.mdb文件(直接ctrl+C就可以進來了)

在demo.mdb數據庫里面建立一張表,名字demo,表結構如下:

新建一個類,名叫DBController.java
import java.io.ByteArrayInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
public class DBController
{
public void Insert(String value)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=demo.mdb";
Connection con = DriverManager.getConnection(database, "", "");
String sql = "INSERT INTO DEMO (NAME,MEMO) VALUES(?,?)";
PreparedStatement pstm = null;
pstm = con.prepareStatement(sql);
pstm.setString(1, "Dr.Oops");
ByteArrayInputStream stream = new ByteArrayInputStream(value
.getBytes());
pstm.setBinaryStream(2, stream, stream.available());
pstm.execute();
pstm.close();
con.close();
}
catch (Exception e)
{
System.out.println("Error: " + e);
}
}
public String Select(String id)
{
String memo = null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=demo.mdb";
Connection con = DriverManager.getConnection(database, "", "");
Statement s = con.createStatement();
s.execute("select ID,NAME,MEMO from DEMO where ID=" + id);
ResultSet rs = s.getResultSet();
if (rs != null)
{
while (rs.next())
{
byte[] image = rs.getBytes(3);
memo = new String(image, "gb2312");
}
}
s.close();
con.close();
}
catch (Exception e)
{
System.out.println("Error: " + e);
}
return memo;
}
}
新建一個TestMe.java文件
import junit.framework.TestCase;
public class TestMe extends TestCase
{
public void test()
{
DBController controller = new DBController();
controller.Insert("nice to meet you!");
System.out.println(controller.Select("1"));
}
}
然后Run as JUnit

posted @
2007-09-09 10:17 張辰 閱讀(494) |
評論 (0) |
編輯 收藏
Oops! Hibernate + Access Quick Start
Purpose:
為了用hibernate鏈接access,花了我一個下午。他nnd,網上一群混蛋,沒有一篇能夠說明為什么的。
Reference:
Eclipse + Access
http://www.tkk7.com/pixysoft/archive/2007/08/30/141392.html
Eclipse + Hibernate
http://www.tkk7.com/pixysoft/archive/2007/09/01/141932.html
Quick Start:
所有的步驟參考上面的文章,幾乎沒有變,下面2個文件修改就行了。
假設我的access數據庫保存在c:\demo.mdb,數據格式:
表名:CUSTOMER
字段:
id 自增,主鍵
username: 文本
password: 文本
則:
Customer.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="Customer" table="CUSTOMER">
<id name="id" column="id">
<generator class="increment" />
</id>
<property name="username" column="USERNAME" />
<property name="password" column="PASSWORD" />
</class>
</hibernate-mapping>
hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory name="java:/hibernate/HibernateFactory">
<property name="show_sql">true</property>
<property name="connection.driver_class">
sun.jdbc.odbc.JdbcOdbcDriver<!-- 這里是Access的JDBCdriverclass名 -->
</property>
<property name="connection.url">
jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)}; DBQ=C:/demo.mdb
</property>
<property name="connection.username">
sa
</property>
<property name="connection.password">
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<mapping resource="Customer.hbm.xml" />
</session-factory>
</hibernate-configuration>
posted @
2007-09-08 17:36 張辰 閱讀(1086) |
評論 (0) |
編輯 收藏