复利计算--结对
Posted 寂静孜御
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了复利计算--结对相关的知识,希望对你有一定的参考价值。
结对次数 | 卓炜杰 | 容杰龙 | 预计编程时间(H) | 结对编程时间(H) | 总结 |
1 | 编码 | 指导、查询资料 | 2 | 2 | 实现组合投功能 |
2 | 编码、查找资料 | 指导、安装SQL2012 | 10 | 6 | 实现数据库连接,插入数据 |
3 | SQL数据读写、编码、查找网络资料 | 指导、背景图片插入、预设数据 | 2 | 3 | 实现数据库读写、预设数据、背景图片设置 |
结对照片 :
关键配置:
hibernate.cfg.xml:
1 <?xml version=\'1.0\' encoding=\'utf-8\'?> 2 <!DOCTYPE hibernate-configuration PUBLIC 3 "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 4 "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> 5 6 <hibernate-configuration> 7 8 <session-factory> 9 10 <!-- Database connection settings --> 11 <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property> 12 <property name="connection.url">jdbc:sqlserver://localhost:1433;databaseName=Fuli</property> 13 <property name="connection.username">eclipse</property> 14 <property name="connection.password">eclipse</property> 15 16 17 <!-- SQL dialect --> 18 <property name="dialect">org.hibernate.dialect.Oracle10gDialect</property> 19 20 21 <!-- Disable the second-level cache --> 22 <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property> 23 24 <!-- Echo all executed SQL to stdout --> 25 <property name="show_sql">true</property> 26 27 <!-- Drop and re-create the database schema on startup --> 28 <!-- <property name="hbm2ddl.auto">update</property> --> 29 30 <mapping resource="Fuli/SQL_mainFrame.hbm.xml"/> 31 </session-factory> 32 33 </hibernate-configuration>
SQL_mainFrame.hbm.xml:
1 <?xml version="1.0"?> 2 <!DOCTYPE hibernate-mapping PUBLIC 3 "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 4 "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> 5 6 <hibernate-mapping package="Fuli"> 7 <class name="W_SQL_mainFrame" table="Fuli_User_mainFrame"> 8 <id name="CS" column="CS"></id> 9 <property name="P" column="P"></property> 10 <property name="i" column="i"></property> 11 <property name="n" column="n"></property> 12 <property name="A" column="A"></property> 13 <property name="F" column="F"></property> 14 </class> 15 </hibernate-mapping>
W_SQL_mainFrame.java:
1 public class W_SQL_mainFrame { 2 private int CS; 3 private float P; 4 private float i; 5 private float n; 6 private float A; 7 private float F; 8 public W_SQL_mainFrame() { 9 super(); 10 // TODO Auto-generated constructor stub 11 } 12 public W_SQL_mainFrame(int CS, double P, double i,double n,double A,double F) { 13 super(); 14 this.CS = CS; 15 this.P = (float) P; 16 this.i = (float) i; 17 this.n = (float) n; 18 this.A = (float) A; 19 this.F = (float) F; 20 } 21 public int getCS() { 22 return CS; 23 } 24 public void setCS(int CS) { 25 this.CS = CS; 26 } 27 public float getP() { 28 return P; 29 } 30 public void setP(double P) { 31 this.P = (float) P; 32 } 33 public float geti() { 34 return i; 35 } 36 public void seti(double i) { 37 this.i = (float) i; 38 } 39 public float getn() { 40 return n; 41 } 42 public void setn(double n) { 43 this.n = (float) n; 44 } 45 public float getA() { 46 return A; 47 } 48 public void setA(double A) { 49 this.A = (float) A; 50 } 51 public float getF() { 52 return F; 53 } 54 public void setF(double F) { 55 this.F = (float) F; 56 } 57 }
SQL_mainFrame.java
1 package Fuli; 2 3 import java.util.List; 4 5 import org.hibernate.Session; 6 import org.hibernate.SessionFactory; 7 import org.hibernate.SharedSessionContract; 8 import org.hibernate.cfg.Configuration; 9 10 11 public class SQL_mainFrame { 12 public static void write(int CS,double P,double i,double n,double A,double F){ 13 14 W_SQL_mainFrame WS=new W_SQL_mainFrame(); 15 WS.setA(A); 16 try{ 17 WS.setCS(CS); 18 WS.setF(F); 19 WS.seti(i); 20 WS.setn(n); 21 WS.setP(P);} 22 catch(Exception e){ 23 CS++; 24 WS.setCS(CS); 25 WS.setF(F); 26 WS.seti(i); 27 WS.setn(n); 28 WS.setP(P); 29 } 30 Configuration cfg = new Configuration(); 31 SessionFactory sf = cfg.configure().buildSessionFactory(); 32 Session session = sf.openSession(); 33 session.beginTransaction(); 34 session.save(WS); 35 session.getTransaction().commit(); 36 session.close(); 37 sf.close(); 38 39 40 } 41 public static double readF() 42 { 43 Configuration cfg = new Configuration(); 44 SessionFactory sf = cfg.configure().buildSessionFactory(); 45 Session session = sf.openSession(); 46 List a=session.createSQLQuery("SELECT F FROM Fuli_User_mainFrame").list(); 47 Object[] obj = (Object[]) a.get(0); 48 double F=(double) obj[0]; 49 return F; 50 } 51 public static double readi() 52 { 53 Configuration cfg = new Configuration(); 54 SessionFactory sf = cfg.configure().buildSessionFactory(); 55 Session session = sf.openSession(); 56 List a=session.createSQLQuery("SELECT i FROM Fuli_User_mainFrame").list(); 57 Object[] obj = (Object[]) a.get(0); 58 double i=(double) obj[0]; 59 return i; 60 } 61 62 public static double readn() 63 { 64 Configuration cfg = new Configuration(); 65 SessionFactory sf = cfg.configure().buildSessionFactory(); 66 Session session = sf.openSession(); 67 List a=session.createSQLQuery("SELECT n FROM Fuli_User_mainFrame").list(); 68 Object[] obj = (Object[]) a.get(0); 69 double n=(double) obj[0]; 70 return n; 71 } 72 public static double readA() 73 { 74 Configuration cfg = new Configuration(); 75 SessionFactory sf = cfg.configure().buildSessionFactory(); 76 Session session = sf.openSession(); 77 List a=session.createSQLQuery("SELECT A FROM Fuli_User_mainFrame").list(); 78 Object[] obj = (Object[]) a.get(0); 79 double A=(double) obj[0]; 80 return A; 81 } 82 public static double readP() 83 { 84 Configuration cfg = new Configuration(); 85 SessionFactory sf = cfg.configure().buildSessionFactory(); 86 Session session = sf.openSession(); 87 List a=session.createSQLQuery("SELECT P FROM Fuli_User_mainFrame").list(); 88 Object[] obj = (Object[]) a.get(0); 89 double P=(double) obj[0]; 90 return P; 91 } 92 }
测试结果:
总结:
在读取SQL数据仍有部分Bug,Fixing...
以上是关于复利计算--结对的主要内容,如果未能解决你的问题,请参考以下文章