⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customerlistingds.java

📁 噶额外噶外骨骼感广泛高热感 就 啊啊
💻 JAVA
字号:
package itso.javadb;
import java.sql.*;

/**
 * @author UELI
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class CustomerListingDS {
	static String dbtab = "CUSTOMER";
	
	public static void main(String[] args) {
		System.out.println("Customer Listing for " + dbtab);

		Connection con = null;
		con = connect();

		Statement stmt = null;
		ResultSet rs = null;
		String select = "SELECT * FROM ITSO." + dbtab;
		try {
			stmt = con.createStatement();
			rs = stmt.executeQuery(select);
			while (rs.next()) {
				String firstName = rs.getString("firstName");
				String lastName = rs.getString("lastName");
				String userID = rs.getString("userID");
				System.out.println(firstName + " " + lastName + " " + userID);
			}
			System.out.println("End of Listing");
		} catch (Exception e) {
			System.err.println("Exception: " + e.getMessage());
		} finally {
			try {
				if (rs   != null) rs.close();
				if (stmt != null) stmt.close();
				if (con  != null) con.close();
			} catch (SQLException e) {}
		}
	}
	
	protected static Connection connect() {
		Connection con = null;
		try {
			javax.naming.InitialContext ctx = new javax.naming.InitialContext();
			javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/mybank");
			con = ds.getConnection();
		} catch (javax.naming.NamingException e) {
			System.err.println("Naming-Exception: " + e.getMessage());
		} catch (java.sql.SQLException e) {
			System.err.println("SQL-Exception: " + e.getMessage());
		}
		return con; 
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -