Topic: 我调了n天了,MSSQLServer的驱动注册不上!哪位大哥帮忙看看

  Print this page

1.我调了n天了,MSSQLServer的驱动注册不上!哪位大哥帮忙看看 Copy to clipboard
Posted by: NUAA_SG
Posted on: 2004-05-28 13:25

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配合使用时也可以看到数据库中的数据。

2.Re:我调了n天了,MSSQLServer的驱动注册不上!哪位大哥帮忙看看 [Re: NUAA_SG] Copy to clipboard
Posted by: tintin365
Posted on: 2004-06-06 20:58

没有用户名和密码吗,这最起码是个错

3.Re:我调了n天了,MSSQLServer的驱动注册不上!哪位大哥帮忙看看 [Re: NUAA_SG] Copy to clipboard
Posted by: tintin365
Posted on: 2004-06-06 20:59

java.sql.SQLException: No suitable driver
这个错多半是url写的不对或用户名密码个数不搭配

class.forname如果用异常就是no class found exception

4.Re:我调了n天了,MSSQLServer的驱动注册不上!哪位大哥帮忙看看 [Re: NUAA_SG] Copy to clipboard
Posted by: nikolai
Posted on: 2004-06-23 13:43

NUAA_SG wrote:
url=new String("jdbc:micorsoft:sqlserver://localhost:1433");
drivername=new String("com.microsoft.jdbc.sqlserver.SQLServerDriver");


你的url写错了,看了半天才发现的晕,居然会这么低级的错误

还有你的用户,密码了

5.Re:我调了n天了,MSSQLServer的驱动注册不上!哪位大哥帮忙看看 [Re: NUAA_SG] Copy to clipboard
Posted by: NUAA_SG
Posted on: 2004-06-28 13:39

不好意思,这个问题我早就解决了,呵呵,谢谢大家


   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