1.你要将安装oracle目录下的jdbc\lib\classes12.zip(数据库driver)和nls_charset12.zip(字符集),两个文件的完整路径在classpath中设置。(如果你的tomcat不支持.zip,要将.zip改为.jar)。2.用下面的连接中的oracle的例子测试一下。
http://www.csdn.net/expert/topic/670/670716.xml?temp=.3571741
http://www.csdn.net/expert/topic/670/670716.xml?temp=.3571741
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@192.168.4.105:1521:dbName"; String user="uNane";
String password="pass";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
%>
classpath已经设置了
不是j2se中已经有了jdbc了吗?
你在java目录下再建一目录jdbc然后
把classes111.zip考到jdbc下,然后设置路径就可以连接了<%
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@192.168.4.105:1521:dbName"; String user="uNane";
String password="pass";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement();
%>
================================
这个采用数据源,需要先配置好。
Hashtable ht = new Hashtable(); ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory"); ht.put(Context.PROVIDER_URL,"t3://localhost:7001"); try { Context ctx = new InitialContext(ht); DataSource ds = (DataSource)ctx.lookup("Oracle"); Connection con = ds.getConnection("system","12345678");//此处是WebLogic7的域用户和密码 Statement st = con.createStatement(); ResultSet res = st.executeQuery("select * from table"); String line = ""; while (res.next()) line = line + res.getString("notes")+"</b>"; out.print(line); con.close(); } catch (Exception ex) { }