Topic: java连接sybase时需要安装哪些东西啊!

  Print this page

1.java连接sybase时需要安装哪些东西啊! Copy to clipboard
Posted by: justforu
Posted on: 2005-04-08 09:38

我的java安装的是j2sdk1.4.2,现在我想连接sybase数据库,我还需要安装其它什么包吗?
我的代码是这样的:
import java.sql.*;
import java.util.Vector;
import sun.jdbc.odbc.*;

public class OdbcConn {
private String driver ;
private String url ;
private String user ;
private String pwd ;

private Connection conn = null ;
private Statement stmt = null ;

public OdbcConn() {

//JDBC-ODBC??
driver = "sun.jdbc.odbc.JdbcOdbcDriver" ;
url = "jdbc:odbc:131.1.6.9:5000/db" ;
user = "sa" ;
pwd = "111" ;

try {
Class.forName(this.driver) ;

conn = DriverManager.getConnection(url,user,pwd) ;

stmt = conn.createStatement() ;
}
catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
public Connection getConnection(){
return this.conn ;
}
public boolean execute(String sql){
boolean rt = false ;
try{
rt = stmt.execute(sql) ;
}
catch(SQLException ex){
ex.printStackTrace() ;
}
return rt ;
}
public int getSize(String sql){
int rt = 0 ;
try {
rt = stmt.executeUpdate(sql);
}
catch (SQLException ex) {
}
return rt ;
}
public ResultSet executeQuery(String sql){
ResultSet rt = null ;
try{
rt = stmt.executeQuery(sql);
}
catch(SQLException ex){
ex.printStackTrace() ;
}
return rt ;
}
public int executeUpdate(String sql){
int rt = 0 ;
try{
rt = stmt.executeUpdate(sql) ;
}
catch(SQLException ex){
ex.printStackTrace() ;
}
return rt ;
}
public void closeConnection(){
try{
stmt.close() ;
conn.close() ;
}
catch(SQLException ex){
ex.printStackTrace() ;
}
}
}

可是他老报错:
Exception in thread "main" java.lang.NoSuchMethodError: main
这是为什么啊?

2.Re:java连接sybase时需要安装哪些东西啊! [Re: justforu] Copy to clipboard
Posted by: why
Posted on: 2005-04-08 10:15

1. try jTDS JDBC driver http://sourceforge.net/projects/jtds/
(check http://jtds.sourceforge.net/faq.html for the class names and URL format used)

or jConnect for Sybase (search on sybase site http://www.sybase.com/ )


2. you don't have a main method, do you?
public static void main(String[] args)

3.Re:java连接sybase时需要安装哪些东西啊! [Re: justforu] Copy to clipboard
Posted by: justforu
Posted on: 2005-04-08 10:37

我把jtds-1.0.2-dist.zip,jtds-1.0.2-src.zip那两个包都下下来了,然后怎么处理啊?谢谢

4.Re:java连接sybase时需要安装哪些东西啊! [Re: justforu] Copy to clipboard
Posted by: 九佰
Posted on: 2005-04-08 11:00

你的程序没有运行入口,
即缺少下面的方法
public static void main(String args[]){
Myapp myapp = Myapp();
}

5.Re:java连接sybase时需要安装哪些东西啊! [Re: justforu] Copy to clipboard
Posted by: justforu
Posted on: 2005-04-08 11:06

我加了还是报错
non-static variable user cannot be referenced from a static context

另外,我下的那两个包要放在哪儿啊?

我是初学,请回答具体一点啊.能不能贴一个你们用过的代码.

6.Re:java连接sybase时需要安装哪些东西啊! [Re: justforu] Copy to clipboard
Posted by: 九佰
Posted on: 2005-04-08 11:16

public static void main(String args[]){
ResultSet myResultSet = null;
String sql ="select * from table";

OdbcConn myapp = OdbcConn();
myResultSet = myapp.executeQuery(sql);
}

增加此方法。

7.Re:java连接sybase时需要安装哪些东西啊! [Re: justforu] Copy to clipboard
Posted by: justforu
Posted on: 2005-04-08 11:22

没有懂什么意思,能不能详细点.多谢.
我下的那两个压缩包没有用吗?

8.Re:java连接sybase时需要安装哪些东西啊! [Re: justforu] Copy to clipboard
Posted by: 九佰
Posted on: 2005-04-08 12:46

你的程序有问题在先,先解决你程序的问题,让她能正常运行;
然后再看是否还存在其他的问题。

加入testMyApp方法,修改main方法如下,进行测试:

public static void main(String args[]){
OdbcConn myapp = OdbcConn();
myapp.testMyApp();
}

public void testMyApp() {
System.out.println("*** test my app is OK");
}


   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