zoukankan      html  css  js  c++  java
  • 千锤百炼软工11.04-11.11

    这周写了我的第一个Dao。第一次和我的数据库链接。下面是我的成果!

    package 新课程添加;
    import java.sql.*;
    import java.util.*;
    import 新课程添加.stunandpaw;
    public class Dao {
        public ArrayList getAllstunumbers() throws Exception{
            Connection conn = null;
            ArrayList<stunandpaw> stunumbers = new ArrayList<stunandpaw>();
            try {
                 Class.forName("com.mysql.jdbc.Driver");
                 String url = "jdbc:mysql://localhost:3306/class?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT";
                 String user = "root";
                 String password = "qwer1234";
                 conn = DriverManager.getConnection(url,user,password);
                 String sql = "select stunumber,password from new_table";
                 Statement stat = conn.createStatement();
                 ResultSet re = stat.executeQuery(sql);
                 while(re.next()) {
                     stunandpaw stp = new stunandpaw();
                     stp.setPassword(re.getString("stunumber"));
                     stp.setStunum(re.getString("password"));
                     stunumbers.add(stp);
                 }
                 re.close();
                 stat.close();
            }catch(SQLException e) {
                e.printStackTrace();
            }finally {
                try {
                    if(conn!=null) {
                        conn.close();
                        conn = null;
                    }
                }catch(Exception ex) {
                    
                }
            }
            return stunumbers;
        }
    }

    显然这个数据库的名字是class,我写的这个小web就是“新课程添加”实现的添加新的课程信息,还有查看课程信息。

  • 相关阅读:
    pdf.js-----后端返回utf-8数据流,前端处理数据展示pdf
    正则表达式之去除前后空格
    ng之邮箱校验
    ng-校验重复并提示具体重复内容
    input 数值框处理
    逻辑之不重复
    ng -----监听变化($scope.$watch())
    js中document的用法
    php中12个魔术方法
    php 中const和 define的区别
  • 原文地址:https://www.cnblogs.com/chaogehahaha/p/14147491.html
Copyright © 2011-2022 走看看