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

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate » MS SQL  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 我调了n天了,MSSQLServer的驱动注册不上!哪位大哥帮忙看看
NUAA_SG





发贴: 8
积分: 0
于 2004-05-28 13:25 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 javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.DriverManager;
import java.io.PrintWriter;
public class MyDataSource implements DataSource
{
String url=null,drivername=null;
Connection con=null;
PrintWriter out=null;
int timeout;
public MyDataSource()
{
url=new String("jdbc:micorsoft:sqlserver://localhost:1433");
drivername=new String("com.microsoft.jdbc.sqlserver.SQLServerDriver");
try
{
Class.forName(drivername);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.print("没有找到相应的"+drivername+"类,产生异常!") ;
System.err.println(e.getMessage()) ;
}
try
{
DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
java.sql.Driver mydriver=DriverManager.getDriver("com.microsoft.jdbc.sqlserver.SQLServerDriver");//这是我调试时加的
}
catch(SQLException sqlex)
{
System.err.print("\n驱动"+drivername+"注册过程中出现异常!\n") ;
System.err.println(sqlex.getMessage()) ;
}
}
public Connection getConnection() throws java.sql.SQLException
{
try
{
con=DriverManager.getConnection(url);
}
catch(SQLException e)
{
System.out.println("\n数据库连接异常\n");
}
return con;
}
public Connection getConnection(String parm1, String parm2) throws java.sql.SQLException
{
try
{
con=DriverManager.getConnection(url,parm1,parm2);
}
catch(SQLException e)
{
System.out.println("\n数据库连接异常\n");
}
return con;
}
public PrintWriter getLogWriter() throws java.sql.SQLException
{
return this.out;
}
public void setLogWriter(PrintWriter parm1) throws java.sql.SQLException
{
this.out=parm1;
}
public void setLoginTimeout(int parm1) throws java.sql.SQLException
{
this.timeout=parm1;
}
public int getLoginTimeout() throws java.sql.SQLException
{
return this.timeout;
}
}
在调用 java.sql.Driver mydriver=DriverManager.getDriver("com.microsoft.jdbc.sqlserver.SQLServerDriver");的时候总是这个驱动总是无法找到!
如果将我自己加的那一部分代码去掉,那么在调用该数据源的getConnection方法时也会出现No Suitable Driver的异常。我调了一天了,眼都花了,哪位大哥帮帮我,小弟不胜感激!
下面是调试中出现的错误:
驱动com.microsoft.jdbc.sqlserver.SQLServerDriver注册过程中出现异常!
No suitable driver
java.sql.SQLException: No suitable driver

at java.sql.DriverManager.getConnection(DriverManager.java:532)

at java.sql.DriverManager.getConnection(DriverManager.java:171)

at database.MyDataSource.getConnection(MyDataSource.java:67)

at database.MainFrame.jButton4_mouseClicked(MainFrame.java:129)

at database.MainFrame_jButton4_mouseAdapter.mouseClicked(MainFrame.java:180)

at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:208)

at java.awt.Component.processMouseEvent(Component.java:5137)

at java.awt.Component.processEvent(Component.java:4931)

at java.awt.Container.processEvent(Container.java:1566)

at java.awt.Component.dispatchEventImpl(Component.java:3639)

at java.awt.Container.dispatchEventImpl(Container.java:1623)

at java.awt.Component.dispatchEvent(Component.java:3480)

at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)

at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3174)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)

at java.awt.Container.dispatchEventImpl(Container.java:1609)

at java.awt.Window.dispatchEventImpl(Window.java:1590)

at java.awt.Component.dispatchEvent(Component.java:3480)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

数据库连接异常

信息: No suitable driver

SQL状态: 08001

错误码: 0

再附加一个说明,驱动中的三个jar包我已经放到了lib的ext中,并且修改了类路径,在调用Class.forName(drivername);的时候并没有抛出异常,所以JB应该是可以找得到驱动的,只是不知为何注册不料,哪位大哥帮忙调调,小弟先谢过了
小弟用的是win2k+JBX+SQLServer7.0,是不是驱动不对啊?不过我在Database Pilot中使用这个驱动可以连通数据库!而且使用Swing的JdbTable以及QueryDataset配合使用时也可以看到数据库中的数据。




Java应用者与<IDE/环境>

话题树型展开
人气 标题 作者 字数 发贴时间
6323 我调了n天了,MSSQLServer的驱动注册不上!哪位大哥帮忙看看 NUAA_SG 4283 2004-05-28 13:25
4887 Re:我调了n天了,MSSQLServer的驱动注册不上!哪位大哥帮忙看看 tintin365 17 2004-06-06 20:58
4912 Re:我调了n天了,MSSQLServer的驱动注册不上!哪位大哥帮忙看看 tintin365 115 2004-06-06 20:59
4852 Re:我调了n天了,MSSQLServer的驱动注册不上!哪位大哥帮忙看看 nikolai 275 2004-06-23 13:43
5323 Re:我调了n天了,MSSQLServer的驱动注册不上!哪位大哥帮忙看看 NUAA_SG 23 2004-06-28 13:39

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