首页 > 数据库技术 > 详细

jdbc

时间:2015-12-11 18:49:25      阅读:283      评论:0      收藏:0      [点我收藏+]

Connection Statement ResultSet 

Look at http://blog.csdn.net/enjoyinwind/article/details/6889523

 

import java.sql.*;

public class Entry {
static final String JDBC_DRIVER = "com.sybase.jdbc3.jdbc.SybDriver";
static final String DB_URL = "jdbc:sybase:Tds:ip:port/database";
static final String USER = "user";
static final String PASS = "passwd";

public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

try {
Class.forName(JDBC_DRIVER);

System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);

System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql = "SELECT id, name FROM test";
rs = stmt.executeQuery(sql);

while (rs.next()) {
int id = rs.getInt("id");
String name = rs.getString("name");

System.out.println("ID: " + id + ", Name: " + name);
}

} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (rs != null)
rs.close();
if (stmt != null)
stmt.close();
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
}

}
}

jdbc

原文:http://www.cnblogs.com/litao9046/p/5039732.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!