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 张辰 阅读(127) |
评论 (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 张辰 阅读(1095) |
评论 (0) |
编辑 收藏
Oops! Bea Sip Server Quick Start Part 2
Purpose
掌握由网页发出sip的invite请求。
Precondition:
http://www.blogjava.net/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 张辰 阅读(770) |
评论 (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 张辰 阅读(838) |
评论 (0) |
编辑 收藏
Oops! JMF Video Cam Quick Start(Java摄像头抓取)
Reference:
Oops! JMF Quick Start
http://www.blogjava.net/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 张辰 阅读(1627) |
评论 (0) |
编辑 收藏
不要看什么TestDriven之类的大道理。。
那些人为了提升一个小小的idea,于是写出了一大堆的废话来忽悠。就像xxx领导的yyy理论一样。
我们程序员需要的是实际。
其实,测试驱动的精髓在于:
不启动整个大型项目能够对某个小方法进行运行调试。
比如我在写一个大型网站,现在要测试数据库的调用之类的,但是我不能每次调试都启动整个网站,时间太长了,怎么办?
1.首先当然要实现了这个数据库调用类。
2.专门写一个testme.java文件,里面初始化这个类,传入参数,然后看结果
3.这个testme.java文件可以遵循JUnit之类的要求。
这样不用在整个项目里面添加一大堆测试类就能够测试了。而且testme.java文件是个临时文件,当测试通过直接就删了。
小结:
我们写程序为了验证某个方法是否可行,经常需要写个小程序去测试,这就是测试驱动。
posted @
2007-09-09 10:22 张辰 阅读(241) |
评论 (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 张辰 阅读(491) |
评论 (0) |
编辑 收藏
Oops! Hibernate + Access Quick Start
Purpose:
为了用hibernate链接access,花了我一个下午。他nnd,网上一群混蛋,没有一篇能够说明为什么的。
Reference:
Eclipse + Access
http://www.blogjava.net/pixysoft/archive/2007/08/30/141392.html
Eclipse + Hibernate
http://www.blogjava.net/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 张辰 阅读(1082) |
评论 (0) |
编辑 收藏