【紧急】如何把Java里填写的数据录入到MySQL数据库中,如何在Java中查看MySQL的数据,回答的好可以加分!
想要实现把录入窗口中的JTextField的内容保存到Mysql数据库中,要求用集合,怎么写呢?集合是Packet;还有查询的时候怎么写从MySQL中查询记录,不需要输入...
想要实现把录入窗口中的JTextField的内容保存到Mysql数据库中,要求用集合,怎么写呢?集合是Packet;还有查询的时候怎么写从MySQL中查询记录,不需要输入条件,直接一条条查看,一样要求用Packet.
代码:
String a = null; //1
String c = null; //2
String d = null; //3
String f = null; //4
String g = null; //5
String h = null; //6
String i = null; //7
String j = null; //8
String k = null; //9
String l = null; //10
String cb1 = null;
String jrb1 = null;
a = this.tf1.getText();//学号
c = this.tf2.getText();//姓名
d = this.tf3.getText();//年龄
f = this.tf4.getText();//家庭住址
g = this.tf5.getText();
h = this.tf6.getText();
i = this.tf7.getText();
j = this.tf8.getText();
k = this.tf9.getText();
l = this.tf10.getText();
cb1 = (String)this.cbx.getSelectedItem();//籍贯
if(r1.isSelected())
jrb1 = "男";
else
jrb1 = "女";
Packet pk = new Packet(a,c,d,f,g,h,i,j,k,l,cb1,jrb1);
alist.add(pk);
Server db = null;
ResultSet rs = null; //处理数据库操作结果集
PreparedStatement pt; //预编译
String sql = "Insert count(*) as count from student where Id = ? and Name = ? and Sex = ? and Jiguan = ? and Lianxi = ? and Zhuanye = ? and Yuanxi = ? and Date =?"; //count:sql里统计行数的函数
try {
pt = (PreparedStatement) db.conn.prepareStatement(sql);
pt.setString(1,a); //给sql语句中的变量赋值
//pt.setString(2,c);
rs =pt.executeUpdate(); 展开
代码:
String a = null; //1
String c = null; //2
String d = null; //3
String f = null; //4
String g = null; //5
String h = null; //6
String i = null; //7
String j = null; //8
String k = null; //9
String l = null; //10
String cb1 = null;
String jrb1 = null;
a = this.tf1.getText();//学号
c = this.tf2.getText();//姓名
d = this.tf3.getText();//年龄
f = this.tf4.getText();//家庭住址
g = this.tf5.getText();
h = this.tf6.getText();
i = this.tf7.getText();
j = this.tf8.getText();
k = this.tf9.getText();
l = this.tf10.getText();
cb1 = (String)this.cbx.getSelectedItem();//籍贯
if(r1.isSelected())
jrb1 = "男";
else
jrb1 = "女";
Packet pk = new Packet(a,c,d,f,g,h,i,j,k,l,cb1,jrb1);
alist.add(pk);
Server db = null;
ResultSet rs = null; //处理数据库操作结果集
PreparedStatement pt; //预编译
String sql = "Insert count(*) as count from student where Id = ? and Name = ? and Sex = ? and Jiguan = ? and Lianxi = ? and Zhuanye = ? and Yuanxi = ? and Date =?"; //count:sql里统计行数的函数
try {
pt = (PreparedStatement) db.conn.prepareStatement(sql);
pt.setString(1,a); //给sql语句中的变量赋值
//pt.setString(2,c);
rs =pt.executeUpdate(); 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询