发表于: 2018-02-04 20:47:25

1 773


今日完成

1. 重新用spring+mybatis+maven写对数据库插入数据的代码

   Dao

public interface MaintestDAO {
public User findUserById(int id) throws IOException;//查询
       public void insertUser(String s, User user) throws  Exception;//增加
       public  void deleteUser(int id) throws  Exception;//删除指定id的记录
       public void updateUser(User user) throws Exception;//更改指定id的数据
}

   实体类

public class User {
private Integer id;
   private String username;

   public User(String username, Date birthday, String sex, String address) {
this.username = username;
       this.birthday = birthday;
       this.sex = sex;
       this.address = address;
   }
private Date birthday;
   private String sex;
   private String address;
   public Integer getId() {
return id;
   }
public void setId(Integer id) {
this.id = id;
   }
public String getUsername() {
return username;
   }
public void setUsername(String username) {
this.username = username;
   }
public Date getBirthday() {
return birthday;
   }
public void setBirthday(Date birthday) {
this.birthday = birthday;
   }
public String getSex() {
return sex;
   }
public void setSex(String sex) {
this.sex = sex;
   }
public String getAddres() {
return address;
   }
public void setAddres(String addres) {
this.address = addres;
   }
@Override
   public String toString() {
return "User{" +
"id=" + id +
", username='" + username + '\'' +
", birthday=" + birthday +
", sex='" + sex + '\'' +
", address='" + address + '\'' +
'}';
   }
}

生成session的类

public class creatsession {
private SqlSessionFactory sqlSessionFactory;
   public SqlSession getSession() throws IOException {
String resource="configmaintest.xml";
       InputStream inputStream= Resources.getResourceAsStream(resource);
       sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream);
       SqlSession sqlSession = sqlSessionFactory.openSession();
       return sqlSession;
   }

   要执行的类

public class maintest{
public static void main(String[] args) throws IOException{
long start=System.currentTimeMillis();
       creatsession i=new creatsession();
       SqlSession sqlSession=i.getSession();
       for (int s=0;s<=10000000;s++){
MaintestDAO maintestDAO = sqlSession.getMapper(MaintestDAO.class);
       User user=new User("ss",null,"m","las");
       sqlSession.insert("test2.insertUser",user);
       sqlSession.commit();
       }
sqlSession.close();
       long end=System.currentTimeMillis();
       System.out.println("程序运行时间: "+(end-start)/1000+"S");
    }
}

   映射文件

<mapper namespace="Dao.MaintestDAO">
   <insert id="insertUser" parameterType="User">
       insert into user(username,birthday,sex,address) values(#{username},#{birthday},#{sex},#{address})
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
           select last_insert_id()
</selectKey>
   </insert>
</mapper>


<mapper namespace="test2">
   <insert id="insertUser" parameterType="User">
       insert into user(username,birthday,sex,address) values(#{username},#{birthday},#{sex},#{address})
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
           select last_insert_id()
</selectKey>
   </insert>
</mapper>

2. 按照昨天的方法导出jar

导入远程服务器后,输入java -jar XXXX.jar 运行,报错:没有主方法;

网上查资料后,用记事本打开jar包中META-INF文件夹下的MANIFEST.MF,修改为

Manifest-Version: 1.0

Main-Class: maintest

     要注意“:”冒号后面必须跟空格;

   再次上传并运行,成功插入一条数据(仅供测试)

然后加入循环分别加入10W和100W条数据

插入10W条数据

 插入100W条数据时,断开链接,运行时间45分钟左右

进入mysql,进行查询;

 对只有10条的表格进行查询

对有120W条数据的表格进行查询

 

现在正在执行插入1000W条数据,明天创建索引,再进行查询比较。

插入1000W条数据失败,进行了2次,都只插入了几十万条,反而第一次插入100W条成功;

3. 学习maven命令;

mvn archetype:generate 创建maven项目

mvnDebug tomcat:run 主要用来远程测试,它会监听远程测试用的8000端口,在eclipse里打开远程测试后,它就会跑起来了,设断点,调试

 mvn dependency:sources 下载依赖包的源代码

 mvn clean package     进入源码目录,运行该命令,生成jar包

mvn test              运行测试

mvn site              产生site
mvn package           打包

 mvn install          在本地Repository中安装jar:
mvn clean            清除产生的项目:
mvn eclipse:eclipse  生成eclipse项目:
mvn idea:idea        生成idea项目:
mvn -Dtest package    组合使用goal命令,如只打包不测试:
mvn test-compile     编译测试的内容:
mvn jar:jar          只打jar包:

明天计划

1. 尝试用maven命令跑单元测试;

2. 学习关于连接池的知识;

遇到问题

阿里云服务器隔几分钟没操作就断掉,找了很多资料没有解决

收获



返回列表 返回列表
评论

    分享到