//数据库类的开始
class DataBaseManager
{
Connection con;
ResultSet rs;
Statement stmt;
public DataBaseManager()
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){} try{ con=DriverManager.getConnection("jdbc:odbc:demo","","");
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
}
catch(SQLException sqle)
{
System.out.println(sqle.toString());
}
}
public ResultSet getResult(String strSQL)
{
try{
rs=stmt.executeQuery(strSQL);
return rs;
}
catch(SQLException sqle)
{
System.out.println(sqle.toString());
return null;
} }
public boolean updateSql(String strSQL)
{
try{
stmt.executeUpdate(strSQL);
con.commit();
return true;
}
catch(SQLException sqle)
{
System.out.println(sqle.toString());
return false;
}
}
public void closeConnection()
{
try
{
con.close();
}
catch(SQLException sqle)
{
System.out.println(sqle.toString());
}
}
} //数据库类的结束
按下B4按钮的处理程序
:
if(e.getSource()==b4)
{
{
strSQL="select * from meeting";
strSql=null;
{
strSql=strSQL;
}
} }
try
{
//首先要删除table中的数据先:
int rowCount=defaultModel.getRowCount()-1;//取得table中的数据行;
int j=rowCount;
for(int i=0;i <=rowCount;i++)
{
defaultModel.removeRow(j);//删除rowCount行的数据;
defaultModel.setRowCount(j);//重新设置行数;
j=j-1;
}
rs=db.getResult(strSql);
while(rs.next())
{
Vector data=new Vector();
data.addElement(rs.getDate(1));
data.addElement(rs.getString(2));
data.addElement(rs.getString(3));
data.addElement(rs.getString(4));
defaultModel.addRow(data);
}
table.revalidate();
} catch(SQLException sqle)
{
System.out.println(sqle.toString());
}
catch(Exception ex)
{
System.out.println(ex.toString());
} }
急!急!急! 我想把这两个程序改成C/S结构,数据库放在服务器上,B4事件在客户机上,问题就是如何通过Socket接口将B4点击事件 要查询的数据在客户机的JTable中显示!!!
还要用Vector吗????请大侠帮帮忙,本人在做毕业设计,快结题了,十分着急,求求各位帮忙。。给程序提示。。小弟先谢谢了。或者把调试的程序发到小弟邮箱 [email protected]
class DataBaseManager
{
Connection con;
ResultSet rs;
Statement stmt;
public DataBaseManager()
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){} try{ con=DriverManager.getConnection("jdbc:odbc:demo","","");
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
}
catch(SQLException sqle)
{
System.out.println(sqle.toString());
}
}
public ResultSet getResult(String strSQL)
{
try{
rs=stmt.executeQuery(strSQL);
return rs;
}
catch(SQLException sqle)
{
System.out.println(sqle.toString());
return null;
} }
public boolean updateSql(String strSQL)
{
try{
stmt.executeUpdate(strSQL);
con.commit();
return true;
}
catch(SQLException sqle)
{
System.out.println(sqle.toString());
return false;
}
}
public void closeConnection()
{
try
{
con.close();
}
catch(SQLException sqle)
{
System.out.println(sqle.toString());
}
}
} //数据库类的结束
按下B4按钮的处理程序
:
if(e.getSource()==b4)
{
{
strSQL="select * from meeting";
strSql=null;
{
strSql=strSQL;
}
} }
try
{
//首先要删除table中的数据先:
int rowCount=defaultModel.getRowCount()-1;//取得table中的数据行;
int j=rowCount;
for(int i=0;i <=rowCount;i++)
{
defaultModel.removeRow(j);//删除rowCount行的数据;
defaultModel.setRowCount(j);//重新设置行数;
j=j-1;
}
rs=db.getResult(strSql);
while(rs.next())
{
Vector data=new Vector();
data.addElement(rs.getDate(1));
data.addElement(rs.getString(2));
data.addElement(rs.getString(3));
data.addElement(rs.getString(4));
defaultModel.addRow(data);
}
table.revalidate();
} catch(SQLException sqle)
{
System.out.println(sqle.toString());
}
catch(Exception ex)
{
System.out.println(ex.toString());
} }
急!急!急! 我想把这两个程序改成C/S结构,数据库放在服务器上,B4事件在客户机上,问题就是如何通过Socket接口将B4点击事件 要查询的数据在客户机的JTable中显示!!!
还要用Vector吗????请大侠帮帮忙,本人在做毕业设计,快结题了,十分着急,求求各位帮忙。。给程序提示。。小弟先谢谢了。或者把调试的程序发到小弟邮箱 [email protected]
解决方案 »
- 大家有过给comm.jar串口程序打包过吗?用myeclipes...
- 请问各位;java在程序中如何查看本机的进程ID
- 【求】词法分析和语法分析的JAVA代码
- 急:关于HttpUrlConnection 各位达人帮帮忙! 在线等
- 在eclipse3.0中如何改变xml和jsp的字体。
- 做B/S的进来看一看!谢谢!
- 一个Frame里有一个exitButton,点击后弹出消息框OK:退出 CANCLE:返回?大家快来帮忙啊!!
- 赋值语句的一点疑问
- 各位同志:JTextArea 怎么没有textChanged事件?要实现是用documentListener吗?
- 各位大侠,谁告诉我答案我请他吃糖啊!!!
- sql语句中order by的问题
- 怎样编写这个有用的JAVA程序
con=DriverManager.getConnection("jdbc:odbc:demo","","");
要不就在客户端建odbc源
我用的是SQL SERVER2000 谢谢!
然后将
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
改为
Class.forName("net.sourceforge.jtds.jdbc.Driver");
再将
con=DriverManager.getConnection("jdbc:odbc:demo","","");
改成
con=DriverManager.getConnection("jdbc:jtds:sqlserver://[hostname]:1433/demo","","");//将[hostname]改为你的服务器名
//另外你确定不要密码么?
一切OK啦