jili1231 2019-03-24 22:38 采纳率: 66.7%
浏览 356
已采纳

LogicalStation station=new LogicalStation();获取不到LogicalStation的值,全是null是为啥?

public class LogicalStationDao {

private static String url ="jdbc:mysql://localhost:3306/lianxi?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
  private static String user = "root";
  private static String password = "root";

  public static void Test(){

      LogicalStation station=new LogicalStation();//

      List<LogicalStation> list=TestRunPoi.read();

    Connection conn = null;
    PreparedStatement ps =null;
    int j=0;
    try {
      Class.forName("com.mysql.jdbc.Driver");
      conn = DriverManager.getConnection(url, user, password);  
      int batchSize = 5000; 
      String sql = "insert into jz (name, city, netWork_type, Site_type,longitude,latitude,manufacturers,Station_name) values(?, ?, ?, ?,?,?,?,?)";
      ps = conn.prepareStatement(sql);
      Long startTime = System.currentTimeMillis();
      conn.setAutoCommit(false);
      for (int i = 0; i<list.size(); i++) {

          ++j;
          ps.setString(1, station.getName());
            ps.setString(2, station.getCity());
            ps.setString(3, station.getNetWork_type());
            ps.setString(4, station.getSite_type());
            ps.setString(5, station.getLongitude());
            ps.setString(6, station.getLatitude());
            ps.setString(7, station.getManufacturers());
            ps.setString(8, station.getStation_name());
            ps.addBatch();
             if ( j % batchSize == 0 ) {
                 ps.executeBatch();
                  conn.commit();


      }

      }
      if ( j % batchSize != 0 ) {
            ps.executeBatch();
            conn.commit();
            Long endTime = System.currentTimeMillis();
              System.out.println("用时:" + (endTime - startTime));
        }
    } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e);
    }finally{
      if(ps!=null){
        try {
          ps.close();
        } catch (SQLException e) {
          e.printStackTrace();
          throw new RuntimeException(e);
        }
      }
      if(conn!=null){
        try {
          conn.close();
        } catch (SQLException e) {
          e.printStackTrace();
          throw new RuntimeException(e);
        }
      }
    }
  }

》——————————————————————————
public class LogicalStation {

private  String name;// 名称
private   String city;// 城市
private   String netWork_type;
private   String Site_type;
private   String longitude;
private   String latitude;
private    String manufacturers;
private   String Station_name;

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getCity() {
    return city;
}

public void setCity(String city) {
    this.city = city;
}

public String getNetWork_type() {
    return netWork_type;
}

public void setNetWork_type(String netWork_type) {
    this.netWork_type = netWork_type;
}

public String getSite_type() {
    return Site_type;
}

public void setSite_type(String site_type) {
    Site_type = site_type;
}

public String getLongitude() {
    return longitude;
}

public void setLongitude(String longitude) {
    this.longitude = longitude;
}

public String getLatitude() {
    return latitude;
}

public void setLatitude(String latitude) {
    this.latitude = latitude;
}

public String getManufacturers() {
    return manufacturers;
}

public void setManufacturers(String manufacturers) {
    this.manufacturers = manufacturers;
}

public String getStation_name() {
    return Station_name;
}

public void setStation_name(String station_name) {
    Station_name = station_name;
}

@Override
public String toString() {
    return "LogicalStation [name=" + name + ", city=" + city + ", netWork_type=" + netWork_type + ", Site_type="
            + Site_type + ", longitude=" + longitude + ", latitude=" + latitude + ", manufacturers=" + manufacturers
            + ", Station_name=" + Station_name + "]";
}

}

  • 写回答

1条回答 默认 最新

  • 毕小宝 博客专家认证 2019-03-25 09:40
    关注

    首先,应该是你并没有对这个对象的属性进行赋值,检测下read操作是不是没有正确将数据存储到对象中。
    其次,有没有报异常,跟踪异常看看。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程