sybase的那个jdbc驱动如何使用啊,就是那个jconnect 5.5, (200分)

  • 主题发起人 主题发起人 KervenLee
  • 开始时间 开始时间
K

KervenLee

Unregistered / Unconfirmed
GUEST, unregistred user!
另外我下载的sybase的那个jconnect5,如何使用了,我试了很长时间也没有搞定,
那位大侠做过,指点一下?我是新手,还不太明白,在线等候大家的指点,我想和大家交个朋友?qq:83851905;msn:kevinhlj@msn.com
 
将jconnect5.zip解包
然后在CLASSPATH中设置jconn2d.jar的路径
这样就可以使用JDBC for Sybase了
简单操作过程为,比如通过datasource来操作:
Properties props = new Properties();
props.put(Context.PROVIDER_URL,
"ldap://some_ldap_server:238/o=MyCompany,c=US");
props.put(Context.OBJECT_FACTORIES,
"com.sybase.jdbc2.jdbc.SybObjectFactory");
props.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory");
Context ctx = new InitialContext(props);
DataSource dataSource = (DataSource) ctx.lookup("servername=myASE");
//你的Sybase所在的服务器名
Connection conn = dataSource.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery ("SELECT * FROM sysusers");



最简单的操作方式:
Driver driver = (Driver) Class.forName("com.sybase.jdbc2.jdbc.SybDriver").newInstance();
Properties props = new Properties();

props.put("user", "tom");
props.put("password", "123");
con = driver.connect("jdbc:sybase:Tds:192.138.151.39:4444",props);
//主机:端口
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery ("SELECT * FROM sysusers");
其实这些在samples中都可以找到。
LUCKY!
 
jconnect5支持11.9或sybase for linux的版本吗?
 
to zhuny
我按照你说的做了,可是还是不行啊
我设置
classpath="d:/jconnect55/classes/"
我的程序如下:
{
Driver driver = (Driver)Class.forName("com.sybase.jdbc.SybDriver" ).newInstance();
System.out.println( "OK");
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
System.out.println(":没有发现所用的驱动程序");
}
它找不到驱动啊
 
/* ----------------------------------------------------------------------------
* Copyright(c) 2000 MERANT. All rights reserved.
*
* Description:
* JNDI Example for DataDirect JDBC Drivers using the
* File System JNDI provider from Sun Microsystems, Inc.
*
* This Example consists of three parts:
*
* 1. Set up the environment and create the initial File System context.
* This code is required for both the bind and the look up of data sources.
* This is the only part that is different between the two JNDI examples
* (LDAP and FileSystem).
*
* 2. Construct and bind the DataSource. This part is
* normally performed by an administrator (using a JNDI tool).
*
* 3. Look up the data source and establish a connection. Typically,
* applications that use JNDI to connect to a database contain this code.
*
* Remarks:
* For more information about JNDI, consult "The JNDI Tutorial" at
* http://www.java.sun.com
*
* Todo
:
* Adapt this code to your specific environment, it uses SQLServer by default.
*
*/
import com.merant.datadirect.jdbcx.sqlserver.SQLServerDataSource;
//import com.merant.datadirect.jdbcx.db2.DB2DataSource;
//import com.merant.datadirect.jdbcx.sybase.SybaseDataSource;
//import com.merant.datadirect.jdbcx.informix.InformixDataSource;
//import com.merant.datadirect.jdbcx.oracle.OracleDataSource;
import java.util.Hashtable;
import javax.naming.*;
import javax.naming.directory.*;
import java.sql.Connection;
import java.sql.SQLException;
import javax.sql.DataSource;
public class JNDI_FILESYSTEM_Example
{
public static void main(String argv[])
{
String name = "MyDatabase";
// The data source will be bound to this name
try
{
/******************************************************************************
* Part 1. Set up the environment and create the initial File System context. *
******************************************************************************/
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file:d:/org");
System.out.println("Trying to create the naming service initial context");
Context ctx = new InitialContext(env);

/****************************************************************
* Part 2. Construct and bind the DataSource. *
****************************************************************/
//SQLServer DataSources
SQLServerDataSource mds = new SQLServerDataSource();
mds.setDescription("My SQLServerDataSource");
mds.setServerName("MyServer");
mds.setPortNumber(1433);
mds.setDatabaseName("database");
mds.setSelectMethod("cursor");
/*
//DB2 DataSources
DB2DataSource mds = new DB2DataSource();
mds.setDescription("My DB2DataSource");
mds.setServerName("MyServer");
mds.setPortNumber(50000);
mds.setDatabaseName("database");
mds.setCollectionId("collectionid");
mds.setPackageName("packageName");
*/
/*
//DB2 MVS DataSources
DB2DataSource mds = new DB2DataSource();
mds.setDescription("My DB2DataSource");
mds.setServerName("MyServer");
mds.setPortNumber(50000);
mds.setLocationName("location");
mds.setCollectionId("collectionid");
mds.setPackageName("packageName");
*/
/*
//Sybase DataSources
SybaseDataSource mds = new SybaseDataSource();
mds.setDescription("My SybaseDataSource");
mds.setServerName("MyServer");
mds.setPortNumber(5000);
mds.setDatabaseName("database");
mds.setSelectMethod("cursor");
*/
/*
//Oracle DataSources
OracleDataSource mds = new OracleDataSource();
mds.setDescription("My OracleDataSource");
mds.setServerName("MyServer");
mds.setPortNumber(1521);
mds.setDatabaseName("database");
*/
/*
//Informix DataSources
InformixDataSource mds = new InformixDataSource();
mds.setDescription("My InformixDataSource");
mds.setServerName("MyServerHost");
mds.setPortNumber(5000);
mds.setInformixServer("MyInformixServer");
mds.setDatabaseName("database");
*/
System.out.println("Trying to bind for the naming service");
ctx.bind(name, mds);

/*******************************************************************
* Part 3. Look up the data source and establish a connection. *
*******************************************************************/
System.out.println("Checking the JNDI binding");
DataSource ds = (DataSource) ctx.lookup(name);
// *** Driver SPECIFIC CODE ***
// The following code is DataSource Specific.
// It is only used here to print out the DataSource attributes.
// Because this code is specific for Your driver, your applications should not
// contain this code. (If you want to print out the DataSource attributes
// in your code, you should use Java's reflection capabilities.)
//SQLServer DataSources
if (ds instanceof SQLServerDataSource)
{
SQLServerDataSource jmds = (SQLServerDataSource) ds;
System.out.println("description=" + jmds.getDescription());
System.out.println("serverName=" + jmds.getServerName());
System.out.println("portNumber=" + jmds.getPortNumber());
System.out.println("databaseName=" + jmds.getDatabaseName());
System.out.println("selectMethod=" + jmds.getSelectMethod());
System.out.println();
}

/*
//DB2 DataSources
if (ds instanceof DB2DataSource)
{
DB2DataSource jmds = (DB2DataSource) ds;
System.out.println("description=" + jmds.getDescription());
System.out.println("serverName=" + jmds.getServerName());
System.out.println("portNumber=" + jmds.getPortNumber());
System.out.println("databaseName=" + jmds.getDatabaseName());
System.out.println("packageName=" + jmds.getPackageName());
System.out.println("collectionId=" + jmds.getCollectionId());
System.out.println();
}
*/
/*
//DB2 MVS DataSources
if (ds instanceof DB2DataSource)
{
DB2DataSource jmds = (DB2DataSource) ds;
System.out.println("description=" + jmds.getDescription());
System.out.println("serverName=" + jmds.getServerName());
System.out.println("portNumber=" + jmds.getPortNumber());
System.out.println("locationName=" + jmds.getLocationName());
System.out.println("packageName=" + jmds.getPackageName());
System.out.println("collectionId=" + jmds.getCollectionId());
System.out.println();
}
*/
/*
//Sybase DataSources
if (ds instanceof SybaseDataSource)
{
SybaseDataSource jmds = (SybaseDataSource) ds;
System.out.println("description=" + jmds.getDescription());
System.out.println("serverName=" + jmds.getServerName());
System.out.println("portNumber=" + jmds.getPortNumber());
System.out.println("databaseName=" + jmds.getDatabaseName());
System.out.println("selectMethod=" + jmds.getSelectMethod());
System.out.println();
}
*/
/*
//Oracle DataSources
if (ds instanceof OracleDataSource)
{
OracleDataSource jmds = (OracleDataSource) ds;
System.out.println("description=" + jmds.getDescription());
System.out.println("serverName=" + jmds.getServerName());
System.out.println("portNumber=" + jmds.getPortNumber());
System.out.println("databaseName=" + jmds.getDatabaseName());
System.out.println();
}
*/
/*
//Informix DataSources
if (ds instanceof InformixDataSource)
{
InformixDataSource jmds = (InformixDataSource) ds;
System.out.println("description=" + jmds.getDescription());
System.out.println("serverName=" + jmds.getServerName());
System.out.println("portNumber=" + jmds.getPortNumber());
System.out.println("informixServer=" + jmds.getInformixServer());
System.out.println("databaseName=" + jmds.getDatabaseName());
System.out.println();
}
*/
// *** END OF Driver SPECIFIC CODE.
// Try to make a connection
System.out.println("*** Trying to make a connection ***");
Connection con = ds.getConnection("john", "whatever");
System.out.println("Connection established");
con.close();
System.out.println("Connection closed");
}
catch (SQLException se)
{
while (se!=null)
{
System.out.println("vendor code: " + se.getErrorCode());
System.out.println("Message: " + se.getMessage());
System.out.println("SQLState: " + se.getSQLState());
se.printStackTrace();
se=se.getNextException();
}
}
catch (NamingException ne)
{
ne.printStackTrace();
}
} // main
} // JNDI_FILESYSTEM_Example.java
 
嘿嘿
好久没来了。
OK??
我觉得是你的CLASSPATH设置的不对。
最好jconn2d.jar的文件路径写全,比如
CLASSPATH = d:/jConnect-5_5/devclasses/jconn2d.jar;
TRY AGAIN!!
 
顺便问一下,我下了sql server 的jdbc驱动程序。里面好像有好几个jar 文件。我
应该怎么设置我的classpath呢。。。以及如何应用呢!!!谢谢
 
To dhyzf
MS SQL 的驱动只有一个JAR吧。
你只需要设置JSQLConnect.jar的路径到CLASSPATH中去。

假如你下载的驱动的确如你所说,我想其中需要设置的一般只会是其中一个。你逐一排除。
Driver driver = (Driver) Class.forName("com.jnetdirect.jsql.JSQLDriver").newInstance();
Connect con = driver.connect("jdbc:JSQLConnect://"+sHost+"/database=pubs&user=sa", new Properties());
Statement s = con.createStatement();
ResultSet rs = s.executeQuery("SELECT * FROM AUTHORS");
 
后退
顶部