当前位置: 技术问答>java相关
我写的一个用jdbc直接联sybase数据库的程序,但是不行
来源: 互联网 发布时间:2015-04-22
本文导语: 代码如下: import java.sql.*; import com.sybase.jdbcx.*; public class Sybase { public static void main(String args[]) throws Exception { ResultSet rs; String url="jdbc:sybase:tds:202.8.1.88:5000"; Statement stmt; Connection con=null; String query="selec...
代码如下:
import java.sql.*;
import com.sybase.jdbcx.*;
public class Sybase
{
public static void main(String args[]) throws Exception
{
ResultSet rs;
String url="jdbc:sybase:tds:202.8.1.88:5000";
Statement stmt;
Connection con=null;
String query="select * from t_test2";
Class.forName("com.sybase.jdbc2.jdbc.SybDriver").newInstance();
con = DriverManager.getConnection(url,"S1912","888888");
}
}
编译通过了,运行不行,错误如下:
Exception in thread "main" java.sql.SQLException: JZ0D5:装载协议com.sybase.jdbc2.tds.tds时出错。
at com.sybase.jdbc2.ErrorMessage.raiseError
......
一共好几行类似的错误,什么问题呀?
import java.sql.*;
import com.sybase.jdbcx.*;
public class Sybase
{
public static void main(String args[]) throws Exception
{
ResultSet rs;
String url="jdbc:sybase:tds:202.8.1.88:5000";
Statement stmt;
Connection con=null;
String query="select * from t_test2";
Class.forName("com.sybase.jdbc2.jdbc.SybDriver").newInstance();
con = DriverManager.getConnection(url,"S1912","888888");
}
}
编译通过了,运行不行,错误如下:
Exception in thread "main" java.sql.SQLException: JZ0D5:装载协议com.sybase.jdbc2.tds.tds时出错。
at com.sybase.jdbc2.ErrorMessage.raiseError
......
一共好几行类似的错误,什么问题呀?
|
jdbc:sybase:Tds::/
|
String url = "jdbc:sybase:Tds:" + IP + ":" + port + "/" + dbName;
try
{
Driver sybDrv = (Driver) Class.forName "com.sybase.jdbc2.jdbc.SybDriver" ).newInstance();
RemoteOperate.conn = DriverManager.getConnection( url, username, password );
}catch ( Exception sqlex )
{
}
try
{
Driver sybDrv = (Driver) Class.forName "com.sybase.jdbc2.jdbc.SybDriver" ).newInstance();
RemoteOperate.conn = DriverManager.getConnection( url, username, password );
}catch ( Exception sqlex )
{
}
|
jdbc:sybase:tds:202.8.1.88:5000改成jdbc:sybase:Tds:202.8.1.88:5000,这个是大小写敏感的。
|
把驱动加入到CLASSPATH中去!
|
jconn2d.jar
|
Class.forName("com.sybase.jdbc2.jdbc.SybDriver").newInstance();
把.newInstance()去掉看看行不行:)
把.newInstance()去掉看看行不行:)
|
你可以看一下JDK下面的例子:
C:jdk13demojfcTableExample
C:jdk13demojfcTableExample