为什么会报空指针异常呢?
package com.joey.jdbc.goods; import com.alibaba.druid.pool.DruidDataSourceFactory; import com.joey.jdbc.common.DbUtils; import com.joey.jdbc.goods.command.*; import javax.sql.DataSource; import java.io.FileInputStream; import java.net.URLDecoder; import java.sql.Connection; import java.sql.Date; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.Properties; public class GoodsData { public static void main(String[] args) { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; Properties properties = new Properties(); String propertyFile = GoodsData.class.getResource("/druid-config.properties").getPath(); try { propertyFile = new URLDecoder().decode(propertyFile, "UTF-8"); properties.load(new FileInputStream(propertyFile)); DataSource dataSource = DruidDataSourceFactory.createDataSource(properties); conn = dataSource.getConnection(); String sql = "select * from goods"; pstmt = conn.prepareStatement(sql); rs = pstmt.executeQuery(); while (rs.next()) { Integer id = rs.getInt("id"); String name = rs.getString("name"); Float price = rs.getFloat("price"); String desp = rs.getString("desp"); Date create_time = rs.getDate("create_time"); System.out.println(id + " " + name + " " + price + " " + desp + create_time); } } catch (Exception e) { e.printStackTrace(); }finally { DbUtils.closeConnection(rs,pstmt,conn); } } }
34
收起
正在回答 回答被采纳积分+1
2回答
java工程师2020版
- 参与学习 人
- 提交作业 9393 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星