请教 InputStream in=JDBCtools.class.getClass().getClassLoader().getResourceAsStrea
程序代码:
public static Connection getconnection2() throws Exception{ Properties properties=new Properties(); InputStream in= JDBCtools.class.getClass().getClassLoader().getResourceAsStream("jdbc.properties");//这里出错!!! properties.load(in); String user=properties.getProperty("user"); String password=properties.getProperty("password"); String jdbcUrl=properties.getProperty("jdbcUrl"); String driver=properties.getProperty("driver"); Class.forName(driver); return DriverManager.getConnection(jdbcUrl,user,password)
java源程序
程序代码:
public void testResultSet() { Connection conn=null; Statement statement=null; ResultSet rs=null; try { conn=JDBCtools.getconnection2();//这里出错 statement=conn.createStatement(); String sql="SELECTid,name,email,brith" + "FROM customers WHERE id=2"; rs=statement.executeQuery(sql); if(rs.next()){ int id=rs.getInt(1); String name=rs.getString("name"); String email=rs.getString(3); Date brith=rs.getDate(4); System.out.println(id); System.out.println(name); System.out.println(email); System.out.println(brith); } } catch (Exception e) { // TODO 自动生成的 catch 块 e.printStackTrace(); }finally{ JDBCtools.release(rs, statement, conn); } }