标题:请教 InputStream in=JDBCtools.class.getClass().getClassLoader().getRes ...
取消只看楼主
神龙火炬
Rank: 1
来 自:广西柳州
等 级:新手上路
帖 子:13
专家分:5
注 册:2014-11-11
结帖率:100%
 问题点数:0 回复次数:0 
请教 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);
        }
        
        
    }
2014-12-07 21:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-439706-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.269849 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved