2007-01-26

SQL2000 关于 Java JDBC 驱动的安装和设定

来源: CSDN 作者:佚名 评论 0 条
 
conn =
DriverManager.getConnection(getConnectionUrl(),userName,password);

if(conn != null) {

System.out.println ("数据库连接成功!");
}

}catch(Exception ce) {

ce.printStackTrace();
System.out.println ("getConnection() 内部错误跟踪:"
ce.getMessage());
}

return conn;
}

public void display() {

try {

conn = getConnection();
PreparedStatement pstmt =
conn.prepareStatement("update friends set "
"salary = ? where name like ?");
pstmt.setInt(1,10000);
pstmt.setString(2,"李四");
pstmt.executeUpdate();
System.out.println ("李四的记录已经被更新!!");

Statement stmt = conn.createStatement();
ResultSet rs =
stmt.executeQuery("select * from friends");
if(!rs.next()) {
System.out.println ("空表,没有数据!!");
}else {


System.out.print(rs.getString(1) "\t");
System.out.print(rs.getString(2) "\t");
System.out.print(rs.getInt(3) "\t");
System.out.print(rs.getDate(4) "\t");
System.out.print(rs.getInt(5) "\t");
System.out.println ();

while(rs.next()) {

System.out.print(rs.getString(1) "\t");
System.out.print(rs.getString(2) "\t");
System.out.print(rs.getInt(3) "\t");
System.out.print(rs.getDate(4) "\t");
System.out.print(rs.getInt(5) "\t");
System.out.println ();
}
}

}catch(SQLException ce) {

System.out.println (ce);
}
}


public static void main(String[] args) {

CourseAppl retObj = new CourseAppl();
retObj.getConnection();
retObj.display();
}
}

http://blog.csdn.net/allen_l/archive/2007/01/25/1493155.aspx


共2页: 上一页 [1] 2 下一页
(本文仅表明作者个人观点,不代表本站及其管理员立场.) 推荐 收藏 投稿 打印 返回 关闭
上一篇:安装SQL Server 2005实例环境图解  
下一篇:SQL Server和Oracle数据锁定比较
    评论加载中…
 推荐文章
     

网站首页  -  网站地图 -   站长论坛  -  网站投稿  -    -  网站管理
Copyright © 2008 芜湖站长站 All Rights Reserved 皖ICP备07500611号