日期:2014-05-20  浏览次数:20800 次

急 急 急 一个菜鸟(如假包换)求助有关JDBC的的问题!!!
我想用   serve   2000   做数据库,用   JAVA   的swing作界面搞一个比较小的桌面系统,主要想了解一下用   JDBC   怎样操作数据库,好像要下驱动什么的   ,这个我不太懂   ,麻烦你们指点一二,要下什么驱动以及其他要用到的(呵呵,如果你要有的话麻烦发过来一下   ooyygy@163.com),还有就是环境变量的配置问题,我的jdk   现在的配置是path:C:\Program   Files\Java\jdk1.5.0_06\bin;C:\Program   Files\Java\jdk1.5.0_06\jre\bin  
classpath:.;C:\Program   Files\Java\jdk1.5.0_06\lib;C:\Program   Files\Java\jdk1.5.0_06\jre\lib;   用   JDBC   连数据库的时候好像要改变一下吧!
主要是过两天就要放假回家了   我家里可没有连网线   (小地方来的),到时候要是没有缺了啥   我可要赶十来里路上街去网吧求救呀     !!!]
                                                                                谢!谢!谢!  


------解决方案--------------------
看你这么迷茫,我给点代码你了

package com.ddddd.dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
import java.sql.*;
import javax.naming.Context;
import javax.sql.DataSource;
import javax.naming.InitialContext;

public class DB2 {
ResultSet rs;
private Connection con = null;
PreparedStatement ps;
public DataSource ds = null;

public Connection getConnection() {
try {
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup( "java:comp/env ");
ds = (DataSource) envCtx.lookup( "jdbc/dddd ");
con = ds.getConnection();

} catch (Exception ne) {
System.out.println(ne);
}
return con;
}

public static void main(String[] args) {
DB2 db2 = new DB2();
db2.getrs( " select * from xxxx; ");

}
public Statement getStatement(){
try {
con=this.getConnection();
return con.createStatement();
} catch (SQLException e) {
logger.error( "getStatementִ��ʧ�� ");
e.printStackTrace();

}
return null;
}
public void execute(String sql) {
try {

con=this.getConnection();
ps=con.prepareStatement(sql);
ps.execute();

} catch (SQLException ex) {
logger.error( "SQLִ��ʧ��execute: "+sql);
ex.printStackTrace();
} finally {

}
}

public ResultSet getrs(String sql) {
try {
// Common com = new Common();
con = this.getConnection();
ps = con.prepareStatement(sql);

return ps.executeQuery(sql);
} catch (SQLException ex) {
logger.error( "SQLִ��ʧ��getrs: "+sql);
ex.printStackTrace();
} finally {

}
return null;
}

public void close() {
try {
if (ps != null) {
ps.close();
}