最菜的问题jsp通过odbc连数据库?100分送上(100分)

  • 主题发起人 主题发起人 wsmp3
  • 开始时间 开始时间
W

wsmp3

Unregistered / Unconfirmed
GUEST, unregistred user!
我的操作系统是win2000 advance server,sql server数据库
jdk1.3和tomcat4.0,直接安装,没配环境变量,有人告诉我自动配好,运行确实可以看见
那只猫。
我想连sql server数据库,是否要装jdbc,按照我的配置是否安装了jdbc?如果不装
jdbc,怎样连上数据库?取出其中的字段内容。
*请给具体 连库的语句 (不装jdbc),取出一字段内容,你可以假设一库名和其中一个
字段。
 
给你两个例子,一个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:oracle:thin:@gslserver:1521:orcl", "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:odbc: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;
}
 
jdbc-odbc连库,dreamwerver中如何写?如何存放到webapps下的root中?
你的这文件放到什么地方?
 
后退
顶部