求解java问题
package common;import
import
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
//import com.hxtt.global.v;
public class SMADao_up
{
private String className;
private String url;
//private String username;
//private String password;
private String id;
private String name;
private Connection con_up;
private Connection con;
private PreparedStatement pstm;
private ResultSet rs;
private Statement st;
public SMADao_up()
{
try{
className="com.microsoft.sqlserver.jdbc.SQLServerDriver";
Class.forName("com.hxtt.sql.access.AccessDriver");
//String str= "jdbc:access:/c:/database.mdb";
url="jdbc:access:/gbkh.mdb";
}catch(ClassNotFoundException e){
System.out.println("加载数据库驱动程序失败!");
e.printStackTrace();
}
}
public void getCon(){
try {
con_up=DriverManager.getConnection(url);
con_up.setAutoCommit(false);
} catch (SQLException e) {
System.out.println("获取数据库连接失败!");
e.printStackTrace();
}
}
public void getCon_normal()
{
try {
con=DriverManager.getConnection(url,id,name);
con.setAutoCommit(false);
} catch (SQLException e) {
System.out.println("获取数据库连接失败!");
e.printStackTrace();
}
}
/////////////////////////////////////////////////////////////////////////
/**
* 根据sql语句从数据库中取出结果集
* 并封装成二维Vector向量
* @param sql
* @return
*/
public Vector<Vector<TableValue>> DBQuery(String sql)
{
Vector<Vector<TableValue>> v = new Vector<Vector<TableValue>>();
Connection con = null;
try {
con=DriverManager.getConnection(url);
con.setAutoCommit(false);
} catch (Exception e) {
System.out.println("");
e.printStackTrace();
}
ResultSet rs = null;
Statement st = null;
System.out.println(con == null);
try
{
st = con.createStatement();
rs = st.executeQuery(sql);
ResultSetMetaData rsmd=rs.getMetaData();
int i = rsmd.getColumnCount();
while(rs.next())
{
Vector<TableValue> vx = new Vector<TableValue>();
for(int m=1;m<=i;m++)
{
vx.add(rs.getObject(m));
}
vx.add(v);
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
st.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
return v;
}
/**
* 插入,删除,添加都可以使用此方法
* @param sql
* @return
*/
public int upData(String sql)
{
int count = 0;
Connection con = null;
try {
con=DriverManager.getConnection(url);
con.setAutoCommit(false);
//设置事务隔离级别为读已提交
con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
} catch (Exception e) {
System.out.println("");
e.printStackTrace();
}
Statement st = null;
try{
st = con.createStatement();
count = st.executeUpdate(sql);
if(count>0)
();
}catch(Exception e){
try{
con.rollback();
}catch(Exception ee){
ee.printStackTrace();
}
e.printStackTrace();
}
finally{
try{
st.close();
con.close();
}catch(Exception e){
e.printStackTrace();
}
}
return count;
}
public static void main(String[] args){
SMADao_up dao = new SMADao_up();
File f = new File(".");
System.out.println(f.getAbsolutePath());
Vector<Vector<TableValue>> v = dao.DBQuery("select * from 部门");
//System.out.println(v);
//System.out.println("数据库连接成功");
for(int i=0;i<v.size();i++){
for(int j=0;j<v.elementAt(i).size();j++){
System.out.print(v.elementAt(i).elementAt(j));
}
System.out.println();
}
}
}
为什么我的TableValue会报错
我不明白是什么原因