给你两个例子,一个FOR ORACLE,另一个FOR SQLSERVER。
不过你的配置要设好,ORACLE的话,还你把CLASS111。ZIP放到LIB目录下,SQLSERVER我是用的
JDBC-OCBC桥做的。
public static ResultSet getquery ()
throws SQLException, ClassNotFoundException
{
// Load the Oracle JDBC driver
Class.forName ("oracle.jdbc.driver.OracleDriver");
// Connect to the database
// You can put a database name after the @ sign in the connection URL.
Connection conn =
DriverManager.getConnection ("jdbc
racle:thin
gslserver:1521
rcl", "gov", "gov");
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select * from module_info");
// Iterate through the result and print the employee names
rset.next ();
String str_back="";
str_back=rset.getString(2);
return rset;
}
public static String getsqlserver ()
throws SQLException, ClassNotFoundException
{
// Load the Oracle JDBC driver
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
// Connect to the database
// You can put a database name after the @ sign in the connection URL.
Connection conn =
DriverManager.getConnection ("jdbc
dbc:test", "yang", "yang");
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select yang,xg from test");
// Iterate through the result and print the employee names
rset.next ();
String str_back="";
str_back=rset.getString("xg");
return str_back;
}