Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java EE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 SQLServer JDBC 驱动程序的问题
Henry2006





发贴: 9
积分: 0
于 2007-10-03 18:35 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
代码如下:
import java.sql.*;

public class DBConnection
{
  private final String DBDRIVER = "com.microsoft.jdbc.sqlserver.SQLServerDriver" ;
  private final String DBURL = "jdbc:microsoft:sqlserver://127.0.0.1:1433" ;
  private final String DBUSER = "sa" ;
  private final String DBPASSWORD = "" ;
  private Connection conn = null ;
  
  public DBConnection()
  {
    try
    {
      Class.forName(DBDRIVER) ;
      this.conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
    }
    catch (Exception e)
    {
      e.printStackTrace() ;
    }
  }
  public Connection getConnection()
  {
    return this.conn ;
  }

  public void close()
  {
    try
    {
      this.conn.close() ;
    }
    catch (Exception e)
    {
      e.printStackTrace() ;
    }    
  }
};

写一个启动运行类,没问题可以连接但是,DAO模式中会把这些搞成一个
工具类,在调用工具类的时候好像是说加载驱动程序错误。



作者 Re:SQLServer JDBC 驱动程序的问题 [Re:Henry2006]
Henry2006





发贴: 9
积分: 0
于 2007-10-03 19:39 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
问题已解决,是classpath的问题。


作者 Re:SQLServer JDBC 驱动程序的问题 [Re:Henry2006]
wxpsjm





发贴: 4
积分: 0
于 2007-10-28 14:50 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
看一下你的*.jar。。有没有问题。。重新导入一下。。

要是不行。。就用连接池吧。。安全。。速度又快




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923