| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 755 人关注过本帖
标题:为什么我添加的数据只能在重新运行时才看的见
只看楼主 加入收藏
NiceGirl
Rank: 2
等 级:新手上路
威 望:4
帖 子:909
专家分:0
注 册:2006-6-18
收藏
得分:0 
谁让你用linux的啊

[此贴子已经被作者于2006-8-14 0:02:54编辑过]



曾经以为百般艰难,蓦然回首,才发现已飞渡千山。。!
2006-08-13 22:47
咖啡2008
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2006-8-12
收藏
得分:0 

大家再帮我看看这代码杂就删除不了数据啊~~要报错.~~~郁闷!谢谢大家帮忙瞧瞧.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.sql.*;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.*;
import javax.swing.event.*;
class a_JFrame3 extends JFrame
{
connection con=new connection();//连接变量
a_JFrame3_2 jframe3_2;//事例化窗体对象
ResultSet rs;
JTable a_JTable;//声明一个类JTable对象
Vector a_Vector;//声明一个向量对象
JScrollPane a_JScrollPane;//声明一个滚动杠对象
AbstractTableModel a_AbstractTableModel;
JTextField a_JTextField;
String s,s1,sql;
a_JFrame3() throws Exception
{

setTitle("设置读者类别");
final String[] a_String={"读者类别","限借书数"};
a_Vector=new Vector();
a_AbstractTableModel=new AbstractTableModel(){//创建一个动态数组
public int getColumnCount()
{
return a_String.length;

}
public int getRowCount()
{
return a_Vector.size();

}
public String getColumnName(int col)
{
return a_String[col];

}
public void setValueAt(Object value,int row,int column)
{

}
public Object getValueAt(int row, int col)
{
if(!a_Vector.isEmpty())
{
return((Vector)a_Vector.elementAt(row)).elementAt(col);
}
else
return null;
}
};

a_JTable=new JTable(a_AbstractTableModel);
a_JTable.addMouseListener(new j_Actin3());
a_JTable.setToolTipText("当你孤单你会想起我!");//设置帮助提示
a_JTable.setAutoResizeMode(0);
a_JTable.setCellSelectionEnabled(false);//设置单元格选择方式
a_JTable.setShowVerticalLines(true);//设置是否显示单元格间的分割线
a_JTable.setShowHorizontalLines(true);
a_JTable.setAutoResizeMode(1); // 设置表格为自动排列方式
a_JScrollPane=new JScrollPane(a_JTable);
try{

rs=con.getResult("select 读者类别,限借书数 from Readerpoetic");
while(rs.next())
{
Vector a_Vector1=new Vector();
a_Vector1.addElement(rs.getString(1));
a_Vector1.addElement(rs.getString(2));
a_Vector.addElement(a_Vector1);
}
}catch(SQLException sq){
}
Container c=getContentPane();
a_JTextField=new JTextField();
JPanel a_JPanel=new JPanel();
JPanel a_JPanel1=new JPanel();
JButton a_JButton=new JButton("添加");
JButton a_JButton1=new JButton("删除");
JButton a_JButton2=new JButton("更改");
JButton a_JButton3=new JButton("退出");
a_JPanel.setLayout(new BorderLayout());
a_JPanel1.add(a_JButton);
a_JButton.addActionListener(new j_Actin());
a_JButton1.addActionListener(new j_Actin4());
a_JButton2.addActionListener(new j_Actin1());

a_JPanel1.add(a_JButton1);
a_JPanel1.add(a_JButton2);
a_JPanel1.add(a_JButton3);
a_JButton3.addActionListener(new j_Actin2());

c.setLayout(new BorderLayout());
c.add(a_JScrollPane,"Center");
a_JPanel.add(a_JScrollPane,"Center");
c.add(a_JPanel);
c.add(a_JPanel1,BorderLayout.SOUTH);
setSize(280,300);
setResizable(false);
show();
con.closeConnection();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

class j_Actin implements ActionListener{
public void actionPerformed(ActionEvent e){
JFrame.setDefaultLookAndFeelDecorated(true);
a_JFrame3_1 a=new a_JFrame3_1();
a.setLocation(350,200);



}
}
class j_Actin3 extends MouseAdapter{
public void mouseClicked(MouseEvent e){
int x=a_JTable.getSelectedRow();
int y=a_JTable.getSelectedColumn();
s=" "+a_JTable.getValueAt(x,0);
s1=""+a_JTable.getValueAt(x,1);
sql="update Readerpoetic where 读者类别="+"'"+s+"'";
//if(a_JTable.getValueAt(x,y).equals("")==false)
System.out.println("jtable..."+x+","+y+" "+a_JTable.getValueAt(x,0));
System.out.println(sql);
System.out.println(s1);


}
}

class j_Actin4 implements ActionListener{
public void actionPerformed(ActionEvent e){
try{
//String sql="delete * from Bookspoetic where 读者类别='"+s.trim()+"'";
if(con.updateSql("delete from Readerpoetic where 读者类别='"+s.trim()+"'"))
{
JOptionPane.showMessageDialog(null,"删除成功!");
dispose();

}
else
{
JOptionPane.showMessageDialog(null,"删除失败!");
dispose();
}
}
catch(Exception ex )
{System.out.println(sql);}





}

}
class j_Actin1 implements ActionListener{
public void actionPerformed(ActionEvent e){
JFrame.setDefaultLookAndFeelDecorated(true);
new a_JFrame3_2().setLocation(350,200);

jframe3_2.a_JTextField.setText(s);
jframe3_2.a_JTextField1.setText(s1);

//System.out.println("我爱JAVA");

}
}
class j_Actin2 implements ActionListener{
public void actionPerformed(ActionEvent e){
JFrame.setDefaultLookAndFeelDecorated(true);
dispose();


}
}


public static void main(String[] args) throws Exception
{
//JDBCTest.createConnetion();
JFrame.setDefaultLookAndFeelDecorated(true);
new a_JFrame3().setLocation(350,200);


}
}



我是JAVA新手,问题多多!请大家多多帮助,谢谢~~
2006-08-14 14:59
快速回复:为什么我添加的数据只能在重新运行时才看的见
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.036332 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved