eclipse开发jsp连接Oracle数据库问题

从昨天开始折腾JSP的毕业设计.要连数据库.抄了N本书N个网站最后还是发现不能加载驱动

没办法.问了师傅.说没有文件.最后搞定了.

东西在Oracle/ora92/jdbc/lib里面

直接把这个包里面的东西放到WEB-INF里面就好了

下面是代码

Code:
  1. create table table1(   
  2. test varchar(20),   
  3. test1 varchar(20)   
  4. )   
  5.   
  6. insert into table1 (test,test1) value(1,2)   
  7. Code:
    1. <%@ page language="java" contentType="text/html; charset=GB2312"  
    2.     pageEncoding="GB2312"%>   
    3. <%@ page import="java.sql.*"%>   
    4. <%@ page import="java.io.*"%>   
    5. <%@ page import="java.util.*"%>   
    6. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">   
    7. <html>   
    8. <head>   
    9. <meta http-equiv="Content-Type" content="text/html; charset=GB2312">   
    10. <title>Insert title here</title>   
    11. </head>   
    12. <body>   
    13.     
    14.      
    15. <%   
    16. Connection conn=null;   
    17. Statement sql=null;   
    18. ResultSet rs=null;   
    19. String url="jdbc:oracle:thin:@localhost:1521:test";    
    20. //test为你的数据库的SID    
    21. String user="system";    
    22. String password="test";   
    23. String sql1="select * from table1";   
    24. try  
    25.     {   
    26.     Class.forName("oracle.jdbc.driver.OracleDriver");   
    27.     }   
    28.   
    29. catch(ClassNotFoundException e){   
    30.     out.print("123");   
    31. }   
    32.  try  
    33.     {   
    34.      conn= DriverManager.getConnection(url,user,password);   
    35.      sql=conn.createStatement();   
    36.      rs=sql.executeQuery(sql1);   
    37.         
    38.      while(rs.next()) {%>      
    39.      您的第一个字段内容为:<%=rs.getString(1)%>      
    40.      您的第二个字段内容为:<%=rs.getString(2)%>      
    41.      <%}%>    
    42.      <%   
    43.     }   
    44.     
    45. catch(SQLException el)   
    46. {   
    47. out.print(""+el);      
    48. }   
    49.      
    50. %>    
    51.      
    52.     
    53. <%   
    54.   
    55.       
    56.       
    57.       
    58. %>      
    59. </body>      
    60. </html>   
    61.   
    62.   

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值