CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Java >  Web 开发

java/jsp/javscript问题

楼主jxnclhjjxnclhj(eee)2003-12-03 08:25:24 在 Java / Web 开发 提问

我想采用SQLSEVER2000数据库,语言是java/jsp/javscript  
  准备开发个网站,哪位能提供连接数据库的DB.java类,  
  将不胜感谢    
  问题点数:0、回复次数:6Top

1 楼xchfriend(xchfriend)回复于 2003-12-03 08:32:42 得分 0

我用的是jdbc-odbc桥连接数据库的!  
   
  package   sql;  
  import   java.sql.*;  
  public   class   faq  
  {  
  String   url="jdbc:odbc:faq";//把这里的faq改成你的映象数据库名!  
  Connection   con=null;  
  Statement   stmt;  
  ResultSet   rs=null;  
  public   faq()  
  {  
  try  
  {  
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");  
  con=DriverManager.getConnection(url);  
  stmt=con.createStatement();  
  }  
  catch(java.lang.ClassNotFoundException   e)  
  {  
  System.err.println("create():"+e.getMessage());  
  }  
  catch(SQLException   e)  
  {  
  System.err.println("something   error");  
  }  
  }  
   
  public   boolean   executeUpdate(String   sql)  
  {  
  try  
  {  
  stmt.executeUpdate(sql);  
  return   true;  
  }  
  catch(SQLException   e)  
  {  
  System.err.println("aq.executeUpdate:"+e.getMessage());  
  }  
          return   false;  
  }  
   
   
        public   ResultSet   executeQuery(String   sql)  
  {  
        rs=null;  
        try  
        {  
        rs=stmt.executeQuery(sql);  
   
        }  
        catch(SQLException   e)  
        {  
  System.err.println("aq.executeUpdate:"+e.getMessage());  
        }  
        return   rs;  
  }  
   
   
   
   
  public   Statement   getStatement()  
  {  
  return   stmt;  
  }  
   
  public   void   close()  
  {  
  try  
  {  
  rs.close();  
  stmt.close();  
  con.close();  
  }  
  catch(Exception   e)  
  {  
  System.out.println(e.toString());  
  }  
  }  
   
  }Top

2 楼moulinjie1(l)回复于 2003-12-03 08:51:23 得分 0

我有你能给我邮箱吗?发到moulinjie@tom.com.cnTop

3 楼moulinjie1(l)回复于 2003-12-03 08:54:22 得分 0

我该你发一份Top

4 楼jxnclhjjxnclhj(eee)回复于 2003-12-03 09:24:36 得分 0

非常谢谢各位,我的邮箱是jxnclhj@sina.com.cn  
  如果有java.db类发给我,我将不胜感谢Top

5 楼jxnclhjjxnclhj(eee)回复于 2003-12-03 10:07:22 得分 0

我用的是xml数据库,如果谁有兴趣,我可以提供。上楼那位朋友的方法我试了,可以操作。  
  不过,我想表中的每个记录就是一个对象,可以对对象进行操作。例如:返回一个记录集,就是返回一个ArrayList  
  public   static   ArrayList   getObjectList(String   xquery,   HashMap   params,  
  Class   objClass)   throws   Exception   {  
  Session   session   =   null;  
  try   {  
  session   =   IXClientSessionFactory.getSession(host,   port,   username,  
  password);  
  XQueryPreparedStatement   stmt   =   session.createXQueryPreparedStatement(  
  xquery);  
  if   (params   !=   null)   {  
  Iterator   it   =   params.keySet().iterator();  
  while   (it.hasNext())   {  
  String   name   =   (String)   it.next();  
  String   value   =   checkValue(   (String)   params.get(name));  
  stmt.setParameter(name,   value);  
  }  
  }  
  XQueryResultSet   result   =   stmt.executeQuery();  
  ArrayList   list   =   new   ArrayList();  
  XQueryResult   resultNode   =   result.next();  
  while   (resultNode   !=   null)   {  
  Node   node   =   resultNode.getNode();  
  list.add(Translate.XML2Object(objClass,   node));  
  resultNode   =   result.next();  
  }  
  return   list;  
  }   finally   {  
  if   (session   !=   null)   {  
  session.close();  
  }  
  }  
   
  }  
   
  添加表中一行记录,就是添加一个对象,我用xml数据库时用过,不知在SQLserver中有没有用过。我这里有个添加记录的,是xml数据库  
  /**  
    *  
    *   @param   collectionName  
    *   @param   documentName  
    *   @param   xpath  
    *   @param   obj  
    *   @return   returns   an   integer   count   indicating   how   many   nodes/values   have  
    *   been   updated.   If   the   returned   value   is   0,   it   means   nothing   has   been   updated  
    *   @throws   java.lang.Exception  
    */  
  public   static   int   insertObject(String   collectionName,   String   documentName,  
    String   xpath,   Object   obj)   throws   Exception   {  
  Session   session   =   null;  
  try   {  
  Node   node   =   Translate.Object2XML(obj);  
  session   =   IXClientSessionFactory.getSession(host,   port,   username,  
  password);  
  XUpdateStatement   stmt   =   session.createXUpdateStatement();  
  return   stmt.insertBefore(collectionName,   documentName,   xpath,   node);  
  }   finally   {  
  if   (session   !=   null)   {  
  session.close();  
  }  
  }  
  }Top

6 楼wind0209(风のFeeling)回复于 2003-12-03 10:33:30 得分 0

ODBC-JDBC连法,结果集存在VECTOR里返回  
   
  package   feeling;  
   
  import   java.io.*;  
  import   java.sql.*;  
  import   java.util.*;  
  import   javax.sql.*;  
  import   javax.naming.*;  
   
  public   class   Db_conf  
  {  
  public   Connection   conn=null;  
  public   ResultSet   rs=null;  
  public   Statement   stmt   =   null;  
   
  public   Db_conf()  
  {  
  //nothing   now  
  }  
   
  public   void   getConn()  
  {  
  try  
  {  
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");      
        conn=DriverManager.getConnection("jdbc:odbc:webdb","","");  
        stmt   =   conn.createStatement();  
  }  
  catch(SQLException   e)  
  {  
  //do   sth.  
  }  
  catch(Exception   ex)  
  {  
  //do   sth.  
  }  
  }  
   
  public   void   closeConn()  
  {  
  try  
  {  
  if(conn!=null)conn.close();  
  }  
  catch(Exception   e)  
  {  
  //do   sth  
  }  
  }  
   
  public   int   eUpdate(String   sql)  
  {  
  int   stats=0;  
  try  
  {  
  stats=stmt.executeUpdate(sql);  
  }  
  catch(SQLException   e)  
  {  
  //do   sth.  
  }  
  return   stats;  
  }  
   
  public   Vector   eQuery(String   sql)  
  {  
  Vector   tmpV=new   Vector();  
  Vector   tmpV2=null;  
  try  
  {  
  rs=stmt.executeQuery(sql);  
  int   rsColCount=rs.getMetaData().getColumnCount();  
   
  while(rs.next())  
  {  
  tmpV2=new   Vector();  
   
  for(int   i=1;i<=rsColCount;i++)  
  {  
  String   str=rs.getString(i);  
  tmpV2.addElement(str);    
  }  
  tmpV.addElement(tmpV2);  
  }  
  }  
  catch(SQLException   e)  
  {  
  //do   sth.  
  }  
  return   tmpV;  
  }  
  }Top

相关问题

  • java与jsp
  • 求jsp+java分页,
  • 打算做java,jsp
  • 打算做java,jsp
  • java,jsp,jbuild,j2ee,j2se,eju,servlet,javabean,tomcat
  • JSP -> Java 的乱码问题
  • JSP/Java备份数据库
  • jsp......
  • jsp!
  • JSP

关键词

  • 数据库
  • xml数据库
  • jdbc
  • resultnode
  • stmt
  • collectionname
  • documentname
  • executeupdate
  • faq
  • 添加

得分解答快速导航

  • 帖主:jxnclhjjxnclhj

相关链接

  • CSDN Java频道
  • Java类图书
  • Java类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo