标签:
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();
}
}
}
}
标签:
原文地址:http://www.cnblogs.com/litao9046/p/5039732.html