关于Hibernate的一点东西

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/leichaocheng/article/details/5753784

package com.itttop.hibernate;

import java.util.Date;
import java.util.Properties;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.itttop.vo.Student;

public class Test {

 /**
  * @param args
  */
 public static void main(String[] args) {
  //1.得到配置环境
  Configuration cfg = new Configuration();
  //读取xml文件需要单独调用Configure()方法
  cfg.configure();
//  cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
//  cfg.setProperty("hibernate.connection.driver_class", "oracle.jdbc.driver.OracleDriver");
//  cfg.setProperty("hibernate.connection.username", "scott");
//  cfg.setProperty("hibernate.connection.password", "tiger");
//  cfg.setProperty("hibernate.connection.url", "jdbc:oracle:thin:@localhost:1521:orcl");
//  cfg.setProperty("hibernate.hbm2ddl.auto","update");
//  cfg.addResource("com/itttop/vo/Student.hbm.xml");
  
  //2.通过配置环境得到SessionFactory
  SessionFactory factory = cfg.buildSessionFactory();
  
  //3.通过SessionFactory得到Session
//  Session session = factory.openSession();
  Session session = factory.getCurrentSession();
  Student stu = new Student(1L,"雷朝成","男",new Date());
  
  //4.通过Session得到Transaction
  Transaction trans = session.beginTransaction();
  session.save(stu);
  trans.commit();
  
  //5.关闭资料
//  session.close();
//  factory.close();
  
 }
}

展开阅读全文

一点有用的东西

09-27

Imports System.DrawingrnrnPublic Class Form1rnrn Public Structure StaticValuern Public Value As Integerrn Public CurrentTime As Stringrn End Structurernrn 'Public Structure CPUStaticsrn ' Public MinY As Integerrn ' Public MaxY As Integerrn Public CriticalLine As Integerrn Public StaticValues As new ArrayListrn Public RefreshRate As Integerrnrn 'End Structurernrn ' Private CPUStatic As CPUStaticsrn Public Const UNITDISTANCE = 10rn Public Const UNITPOINTS = 4rn Public CPUBitmap As Bitmaprn Public g As Drawing.Graphicsrn Public rdm As New Random()rnrn Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Loadrn CriticalLine = 90rn RefreshRate = 1000rn Timer1.Interval = RefreshRatern Timer1.Enabled = Truern DrawCurve()rn End Subrnrn Sub DrawCurve()rn Dim CPUPoints() As PointFrn If StaticValues.Count <= 0 Then Exit Subrnrn ReDim CPUPoints(StaticValues.Count - 1)rn Dim TotalLength As Integer = PictureBox1.Width / UNITPOINTSrnrn If TotalLength > CPUPoints.Length Thenrn For i As Integer = TotalLength - CPUPoints.Length To TotalLength - 1rn CPUPoints(i - (TotalLength - CPUPoints.Length)).X = UNITPOINTS * irn CPUPoints(i - (TotalLength - CPUPoints.Length)).Y = PictureBox1.Height - StaticValues(i - (TotalLength - CPUPoints.Length)).Value * PictureBox1.Height / 100rn Nextrn Elsern For i As Integer = 0 To TotalLength - 1rn CPUPoints(i - (TotalLength - CPUPoints.Length)).X = UNITPOINTS * irn CPUPoints(i - (TotalLength - CPUPoints.Length)).Y = PictureBox1.Height - StaticValues(i - (TotalLength - CPUPoints.Length)).Value * PictureBox1.Height / 100rn Nextrn End Ifrnrn g.Clear(Color.Black)rn g.DrawLine(Pens.LightGreen, 0, PictureBox1.Height Mod UNITDISTANCE, _rn PictureBox1.Width, PictureBox1.Height Mod UNITDISTANCE)rn For i As Integer = PictureBox1.Height Mod UNITDISTANCE To PictureBox1.Height Step UNITDISTANCErn g.DrawLine(Pens.DarkGreen, 0, i, PictureBox1.Width, i)rn Nextrnrn For i As Integer = UNITDISTANCE To PictureBox1.Width Step UNITDISTANCErn g.DrawLine(Pens.DarkGreen, i, 0, i, PictureBox1.Height)rn Nextrnrn 'draw critical line using RED colorrn Dim CriticalY As Integer = PictureBox1.Height - PictureBox1.Height * CriticalLine / 100rn g.DrawLine(New Pen(Color.Crimson, 2.0), 0, CriticalY, PictureBox1.Width, CriticalY)rnrn If Not CPUPoints Is Nothing Thenrn If CPUPoints.Length > 1 Thenrn g.DrawCurve(Pens.LightYellow, CPUPoints)rn End Ifrn End Ifrnrn PictureBox1.Refresh()rnrn End Subrnrn Sub AddCPUVaue(ByVal CPUValue As StaticValue)rn Dim tempValue As New StaticValuern tempValue = CPUValuern StaticValues.Add(tempValue)rn '假设每秒产生一次数据,一天最多产生86400个rn '这里只保存一天的数据rn If StaticValues.Count > 86400 Thenrn StaticValues.RemoveAt(0)rn End Ifrn End Subrnrn Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tickrn Dim CPUValue As StaticValuern CPUValue.Value = rdm.Next(50, 100)rn CPUValue.CurrentTime = "1"rn AddCPUVaue(CPUValue)rn 'Debug.Print(CPUValue.Value)rn DrawCurve()rnrn End Subrnrn Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resizern If Not CPUBitmap Is Nothing Then CPUBitmap.Dispose()rn CPUBitmap = New Bitmap(PictureBox1.Width, PictureBox1.Height)rn g = Drawing.Graphics.FromImage(CPUBitmap)rn PictureBox1.Image = CPUBitmaprn PictureBox1.Refresh()rnrn End SubrnEnd Classrn 论坛

没有更多推荐了,返回首页