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

📄 select.java

📁 电子工业出版社出版的《java2应用开发指南》配套光盘源代码
💻 JAVA
字号:
//Select.java
import java.math.*;
import java.net.URL;
import java.sql.*;

class Select 
{

	 public static void main(String argv[])
	{
		try
		{
		// Create a URL specifying an ODBC data source name.
		String url = "jdbc:odbc:wombat";

		// Connect to the database at that URL.
		Connection con = DriverManager.getConnection(url, "kgh", "");

		// Execute a SELECT statement
		Statement stmt = con.createStatement();
		ResultSet rs = stmt.executeQuery("SELECT a, b, c, d, key FROM Table1");

		// Step through the result rows.
		System.out.println("Got results:");
		while (rs.next())
		{
			// get the values from the current row:
		    	int a = rs.getInt(1);
			BigDecimal b = rs.getBigDecimal(2);
			char c[] = rs.getString(3).toCharArray();
			boolean d = rs.getBoolean(4);
			String key = rs.getString(5);
			// Now print out the results:
			System.out.print("  key=" + key);
			System.out.print("  a=" + a);
			System.out.print("  b=" + b);
			System.out.print("  c=");
			for (int i = 0; i < c.length; i++) 
			{
				System.out.print(c[i]);
			}
			System.out.print("  d=" + d);
			System.out.print("\n");
		}

		stmt.close();
		con.close();
		}
		catch (java.lang.Exception ex)
		{
			ex.printStackTrace();
		}
	 }
}

⌨️ 快捷键说明

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