Ecllipse

**

Ecllipse开发:

**

  1. 列表内容
    JPA Project

编码选择
如果要使插件开发应用能有更好的国际化支持,能够最大程度的支持中文输出,则最好使 Java文件使用UTF-8编码。然而,Eclipse工作空间(workspace) 的缺省字符编码是操作系统缺省的编码,简体中文操作系统 (Windows XP、Windows 2000简体中文)的缺省编码是GB18030,在此工作空间中建立的工程编码是GB18030,工程中建立的java文件也是GB18030。如果要使 新建立工程、java文件直接使UTF-8则需要做以下工作:
1、windows->Preferences…打开”首选项”对话框,左侧导航树,导航到general->Workspace,右 侧Text file encoding,选择Other,改变为UTF-8,以后新建立工程其属性对话框中的Text file encoding即为UTF-8。
2、windows->Preferences…打开”首选项”对话框,左侧导航树,导航到general->Content Types, 右侧Context Types树,点开Text,选择Java Source File,在下面的Default encoding输入框中输入UTF-8,点Update,则设置Java文件编码为UTF-8。其他java应用开发相关的文件如: properties、XML等已经由Eclipse缺省指定,分别为ISO8859-1,UTF-8,如开发中确需改变编码格式则可以在此指定。
3、经过上述两步,新建java文件即为UTF-8编码,Eclipse编译、运行、调试都没问题,但是做RCP应用的Product输出时、 或者插件 输出时,则总是出错,要么不能编译通过(输出时要重新compile)、要么输出的插件运行时中文显示乱码。此时需要再RCP应用、或插件Plugin工 程的build.properties中增加一行,javacDefaultEncoding.. = UTF-8。让输出时编译知道java源文件时UTF-8编码。这个设置需要保证所有的java源文件时UTF-8编码格式,如果不全是,可以参考 Eclipse帮中(Plug-in Development Environment Guide > Reference > Feature and Plug-in Build configuration),建议全部java源文件是UTF-8编码。
如果插件开发、RCP应用开发原 来基于其他编码,如GB18030,想转换为UTF-8,则首先,做以上工作;然后通过查找编码转换工具,如基于 iconv的批量转换工具,将原编码转换为UTF-8编码,注意只转换java源文件,其他类型文件可能已经是比较合适的编码了;将原工程属性中的 Text file encoding,从原编码改为UTF-8即可

Web:

http://jingyan.baidu.com/article/22fe7ced39550e3002617f30.html
个人博客:GitPages
GitHub+Markdown+Jekyll打造完美的个人博客
http://jingyan.baidu.com/article/ed2a5d1f3732cb09f7be1745.html

微信公众平台开发:
http://www.cnblogs.com/mchina/archive/2013/06/05/3108618.html

hibernate
[转载]在eclipse中用hibernate框架连mysql (2012-11-14 11:28:10)转载▼
标签: 转载
原文地址:在eclipse中用hibernate框架连mysql作者:hwago
此例子为多对一单向关联;
也即多个学生可有一个老师来教;
在运行此例子时;
条件一:mysql中,存在localhost 的root 用户,密码为:123456,//–此项如果没有,要自行修改hibernate.cfg.xml中的用户登录信息;
条件二:JDK的版本在1.5.0以上,;Eclipse 3.0以上为最佳;如果使用MyEclipse 2.0以上(其它IDE另当别论)就更好;
如果没有Mysql JDBC的话,到我的资源上去下载;如果改用其它的数据库,一样适用,但hibernate.cfg.xml要修改,对于初学者来说,在不会MyEclipse 自动生成配置文件之前;最好先用Mysql;在此介绍一下,mysql client的登录语句:MS: Mysql -hlocalhost -uroot -p123456(附加:MS 在后面均指MYSQL语句);

创建数据库:MS:create database iyvbb ;

创建学生表:MS:create table student( id integer not null auto_increment,studentName varchar(255), teacher_id integer,primary key(id) );

创建老师表:MS:create table teacher(id integer not null auto_increment,teacherName varchar(255), primary key(id) );

第一:打开Eclipse, 文件/新建/项目/选择JAVA项目,进入创建JAVA项目对话框,输入LoaferIyvbb,单击“下一点”进入“JAVA设置”对话框,在项目下新建一文件夹(目的为储存包文件),名为:lib ;

在“JAVA 设置”框中,单击“库”添加自己所需要的库:如mysql 需要:mysql_connection_java.jar文件,Hibernate需要hibernate3.jar文件,还有其它的如:log4j.jar ,cmt.jar,jboos.jar。。。此处不多介绍;之后,单击“完成”即可创建新的项目;

第二:把所需要的包文件,复制到:lib目录下,然后右击“LoaferIyvbb”项目,选择“属性”,进入“LoaferIyvbb属性“对话框中,选择Java 构建路径 项,之后,单击“库”文件,把刚才复制到:lib下的包,添加到项目中去,之后,保存完成包的加载;右击项目,创建源文件夹src,

结构图:
-LoaferIyvbb
|-src
|-com
|-HibernateSessionFactory.java
|-com.loafer.iyv
|-AbstractStudent.java
|-AbstractTeacher.java
|-ServiceSelect.java
|-Student.java
|-Teacher.java
|-Student.hbm.xml
|-Teacher.hbm.xml
|-hibernate.cfg.xml
|-log4j.properties
|-lib
|-包
…..

第三:在项目中,新建包:包名为;com和com.loafer.iyv;在包com中,创建类:HibernateSessionFactory.java文件(此文件为工厂会话集);代码如下:


package com;//此文件在com包下;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;

public class HibernateSessionFactory {
private static String CONFIG_FILE_LOCATION = “/hibernate.cfg.xml”;
private static final ThreadLocal threadLocal = new ThreadLocal();
private static Configuration configuration = new Configuration();
private static org.hibernate.SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION;
static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println(“%%%% Error Creating SessionFactory %%%%”);
e.printStackTrace();
}
}
private HibernateSessionFactory() {
}

public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();

if (session == null || !session.isOpen()) { if (sessionFactory == null) { rebuildSessionFactory(); } session = (sessionFactory != null) ? sessionFactory.openSession()

null;
threadLocal.set(session);
}

return session;
}

public static void rebuildSessionFactory() {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println(“%%%% Error Creating SessionFactory %%%%”);
e.printStackTrace();
}
}

public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);

if (session != null) {
session.close();
}
}

public static org.hibernate.SessionFactory getSessionFactory() {
return sessionFactory;
}

public static void setConfigFile(String configFile) {
HibernateSessionFactory.configFile = configFile;
sessionFactory = null;
}

public static Configuration getConfiguration() {
return configuration;
}

}


并在项目的要目录下创建:Hibernate.cfg.xml文档;代码如下:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值