Java核心代码例程之:JDBC.java
2008-01-05 08:39:41 来源:WEB开发网核心提示:import java.sql.*;/** * Simple demo of how to perform a SQL query using JDBC. **/public class JDBC{ public static void main(String args[]) throws Exception {Cla
import java.sql.*;
/**
* Simple demo of how to perform a SQL query using JDBC.
**/
public class JDBC
{
public static void main(String args[]) throws Exception
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:EmpPRjDB", "admin", "letmein");
Statement stmt = conn.createStatement();
ResultSet rslt = stmt.executeQuery("SELECT name, city FROM employee");
while (rslt.next())
{
System.out.println("Hello World from "
+ rslt.getString(1) // You can use getString(columnNumber)
+ " in "
+ rslt.getString("city")); // Or, you can use getString(columnName)
}
rslt.close();
stmt.close();
conn.close();
}
}
更多精彩
赞助商链接