• eclipse ssh连接sqlserver express


    public static String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    public static String url = "jdbc:sqlserver://ender-pc\sqlexpress:1433;DatabaseName=test;";
    public static String user = "sa";
    public static String pwd = "xx2000";

    一定要手动设置sqlexpress的端口号为1433

    protocols for sqlexpress->tcp-ip->ip all->1433

    另外在创建Hibernate Console Configuration 时出现could not parse configuration ...hibernate.cfg.xml的错误提示时

    估计要把hibernate.cfg.xml中的doctype头设置为本地dtd如下:

    d:j2ee_workspace estdtdhibernate-configuration-3.0.dtd

    当然要建立dtd文件夹,并把hibernate-configuration-3.0.dtd文件拷贝到dtd文件夹中

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"><!-- 或者d:dtdhibernate-configuration-3.0.dtd -->
    <hibernate-configuration>
    <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.SQLServer2012Dialect</property>
    <property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
    <property name="hibernate.connection.password">en2000</property>
    <property name="hibernate.connection.url">jdbc:sqlserver://ender-pcsqlexpress:1433;databaseName=test</property>
    <property name="hibernate.connection.username">sa</property>
    <property name="hibernate.use_sql_comments">true</property>
    <property name="hibernate.show_sql">true</property>
    <!-- <property name="hibernate.hbm2ddl.auto">create</property> -->
    <property name="connection.pool_size">150</property>
    </session-factory>
    </hibernate-configuration>

    另外要注意文件的编码utf-8 ,能被当前项目识别

    注意hbm.xml中类型的转换

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
    <!-- Generated 2015-8-1 22:04:42 by Hibernate Tools 4.3.1 -->
    <hibernate-mapping>
    <class catalog="test" name="User" schema="dbo" table="[user]">
    <id name="id" type="int">
    <column name="Id"/>
    <generator class="assigned"/>
    </id>
    <property generated="never" lazy="false" name="user" type="string">
    <column name="[user]" sql-type="nvarchar(max)"/>
    </property>
    <property generated="never" lazy="false" name="pass" type="string">
    <column name="pass" sql-type="nvarchar(180)"/>
    </property>
    </class>
    </hibernate-mapping>

    插入记录例子

    Configuration cfg = new Configuration().configure().addClass(User.class);

    String sfName = cfg.getProperty(Environment.SESSION_FACTORY_NAME);
    System.out.println("cfname:" + sfName);
    StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
    .applySettings(cfg.getProperties()).build();

    SessionFactory sf = cfg.buildSessionFactory(serviceRegistry);
    Session session = sf.openSession();

    session.beginTransaction();

    User theUser = new User();
    theUser.setId(77);
    theUser.setUser("한국어");
    theUser.setPass("一二三");
    session.save(theUser);


    User theUser1 = new User();
    theUser1.setId(47);
    theUser1.setUser("你麻痹");
    theUser1.setPass("一二三");
    session.save(theUser1);

    session.getTransaction().commit();
    session.close();
    sf.close();

  • 相关阅读:
    常用的站内搜索技术比较
    .NET中读取csv文件内容
    C#编码规范
    处理模型——检测光标是否在模型上
    数据库如何规范命名
    处理顶点——绘制三角形,线和点
    处理模型——根据地形正确倾斜模型
    处理顶点——使用索引移除冗余顶点
    处理顶点——在三角形上添加纹理
    处理模型——通过定义一个自定义的TypeWriter和TypeReader将多个对象存储在Tag属性中
  • 原文地址:https://www.cnblogs.com/coolyylu/p/4687963.html
Copyright © 2020-2023  润新知