WebLogic7的配置:1. 启动WebLogic72. 打开IE6,在地址栏中输入:http://localhost:7001/console3. 输入用户名和密码4. 在左边的目录树中选中Services->JDBC->Connection Pools,单击右侧的Configure a new JDBC Connection Pool.,输入以下信息:Configuration->General页:Name = SQL Server Connection PoolURL = jdbc:weblogic:mssqlserver4:northwind@localhostDriver classname = weblogic.jdbc.mssqlserver4.DriverProperties : user = sa Password = “” <- sa的密码单击Create建立连接池。Targets->Server页:将myserver(服务器名称)移至右侧的列表中,但击单击Apply5. 在左边的目录树中选中Services->JDBC->Data Sources(或者TXData Sources),单击右侧的Configure a new JDBC Connection Pool.,输入以下信息:Configuration->General页:Name = SQLServer Tx Data SourceJNDI Name = SQLServerPool Name = SQL Server Connection Pool选中Emulate Two-Phase Commit for non-XA Driver和Row Prefetch Enabled单击Create建立数据源。Targets->Server页:将myserver(服务器名称)移至右侧的列表中,但击单击Apply,配置完毕。 try { Class.forName("weblogic.jdbc.mssqlserver4.Driver"); Connection con = DriverManager.getConnection("jdbc:weblogic:mssqlserver4:northwind@localhost","sa","");//此处根据你的SQLServer帐户而定。 Statement st = con.createStatement(); ResultSet res = st.executeQuery("select * from employees"); String line = ""; while (res.next()) line = line + res.getString("title")+"\n"; jTextArea1.setText(line); con.close(); } catch (Exception ex) { jTextArea1.setText("error : "+ex.getMessage());}
我给你发个东西就可以了
[email protected]
谢谢
< %@ page contentType="text/html;charset=gb2312"% >
< %@ page import="java.sql.*"% >
< html >
< body >
< %Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs"; //pubs为你的数据库的
String user="sa";
String password="";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {% >
您的第一个字段内容为:< %=rs.getString(1)% >
您的第二个字段内容为:< %=rs.getString(2)% > < %}% >
< %out.print("数据库操作成功,恭喜你");% >
< %rs.close();
stmt.close();
conn.close(); % >
< /body >
< /html >
建议你建立一个数据库源,然后用ejb操作数据库。jsp调用session bean