版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Word———Java实验8实习报告;
privatestaticstatement;
publicstaticsql=deleteSQL;
sql=deletefromstudentwhereSno=?;
try{
statement=conn.prepareStatement(sql);
statement.setString(1,No);
statement.executeUpdate();
statement.close();
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}
package数据库编程;
importjava.sql.Connection;
importjava.sql.DriverManager;
importjava.sql.SQLException;
importjava.util.Scanner;
import数据库编程.Update;
publicclassStudent{
staticStringsql;
publicstaticConnectioncon;
publicStudent(){
try{
Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);
}
catch(ClassNotFoundExceptione){
System.out.print(e);
}
try{
con=DriverManager.getConnection(jdbc:odbc:star,,);
}catch(SQLExceptione){
e.printStackTrace();
}
}
publicstaticvoidmain(String[]args){
StudentstuInfoMan=newStudent();
sql=select*fromstudentwhereSno=?;
Scannerscan=newScanner(System.in);
System.out.println(请输入你要查询的同学的学号);StringNo=scan.nextLine();
Update.Select(No,sql,con);
//查询
System.out.println(输入要插入的学号);
No=scan.next();
System.out.println(输入要插入的姓名);
Stringname=scan.next();
System.out.println(输入要插入的年龄);
intage=scan.nextInt();
sql=insertintostudent(Sno,Sname,Sage)values(?,?,?);Insert.Insert(No,name,age,sql,con);
sql=deletefromstudentwhereSno=?;
System.out.println(输入要删除的学号);
No=scan.next();
Delete.Delete(No,sql,con);
try{
con.close();
}catch(SQLExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}2
package数据库编程;
importjavax.swing.JFrame;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjava.sql.DriverManager;
importjava.sql.ResultSet;
importjava.sql.SQLException;
importjava.sql.Statement;
importjavax.swing.*;
importjava.sql.*;
importcom.sun.corba.se.pept.transport.Connection;
publicclassStudentTestextendsJFrame{
privatestaticfinallongserialVersionUID=1L;Stringid;
Stringname;
intage;
staticConnectioncn=null;
staticStatementstate=null;
staticJTextFieldtext1;
staticJTextFieldtext2;staticJTextFieldtext3;publicStudentTest(){super();getContentPane().setLayout(null);setTitle(同学信息管理系统);setBounds(300,200,400,300);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setVisible(true);JLabellabel1=newJLabel(学号:);JLabellabel2=newJLabel(姓名:);JLabellabel3=newJLabel(年龄:);label1.setBounds(20,20,80,40);getContentPane().add(label1);label2.setBounds(20,80,80,40);getContentPane().add(label2);label3.setBounds(20,140,80,40);getContentPane().add(label3);text1=newJTextField();text2=newJTextField();text3=newJTextField();text1.setBounds(90,30,150,30);getContentPane().add(text1);text2.setBounds(90,90,150,30);getContentPane().add(text2);text3.setBounds(90,150,150,30);getContentPane().add(text3);JButtonb1=newJButton(追加);JButtonb2=newJButton(查询);JButtonb3=newJButton(删除);b1.setBounds(250,30,100,30);getContentPane().add(b1);b2.setBounds(250,90,100,30);getContentPane().add(b2);b3.setBounds(250,150,100,30);getContentPane().add(b3);b1.addActionListener(newadd1());b2.addActionListener(newselect());b3.addActionListener(newdelete());setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}classadd1implementsActionListener{
publicvoidactionPerformed(ActionEventarg0)
{
id=text1.getText();
name=text2.getText();
age=Integer.parseInt(text3.getText());
Stringsql=insertintostudentvalues(+id+,+name+,+age+);;try{
state.executeUpdate(sql);
newJdbc();
}catch(SQLExceptione){
e.printStackTrace();
}
}
}
classselectimplementsActionListener
{
publicvoidactionPerformed(ActionEventq)
{
try{
id=text1.getText();
ResultSetrs=state.executeQuery(select*fromstudentwhereid=+id+);
while(rs.next())
{
Stringname1=rs.getString(name);
intage1=rs.getInt(age);
System.out.println(+name1++age1);
text2.setText(name1);
text3.setText(age1+);
}
}
catch(SQLExceptione){
e.printStackTrace();
}
}
}
classdeleteimplementsActionListener
{
publicvoidactionPerformed(ActionEventw)
{
id=text1.getText();
Stringsq=deletefromstudentwhereid=+id+;try{
state.executeUpdate(sq);
newJdbc();
}catch(SQLExceptione){
e.printStackTrace();
}
}
}
publicstaticvoidmain(String[]args)
{
StudentTesttest=newStudentTest();
test.setVisible(true);
try{
Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);
}catch(ClassNotFoundExceptione){
System.out.print(e);
try{
cn=(Connection)
DriverManager.getConnection(jdbc:odbc:star,,);
state=((java.sql.Connection)cn).createStatement();}
catch(SQLExceptione1){
System.out.println(e1);
}
}
}
}
classJdbcextendsJFrame
{
privatestaticfinallongserialVersionUID=1L;
publicJdbc()
{
super();
setBounds(400,200,400,400);
getContentPane().setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setVisible(true);
JLabellab=newJLabel();
lab.setText(一行受影响);
this.getContentPane().add(lab);
}
}
3.
package数据库编程;
importjava.sql.*;
publicclassTest3{
Connectioncon;
PreparedStatementrs;
try{
Class.forName(sun.jdbc.odbc.JdbcOdbcDriver);}catch(ClassNotFoundExceptione){
System.out.print(e);
}
publicTest3()throwsSQLException{
con=DriverManager.getConnection(jdbc:odbc:star,,);}
publicvoidclose(){
try{
rs.close();
con.close();
}catch(SQLExceptione){
System.out.println(errorinclose!);
System.out.println(e);
}
return;
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 生态养殖项目合作协议
- 审计专业技术资格(高级)综合试题精练(含解析)
- 公路水运工程试验检测师《公共基础》模拟试卷(带评分标准)
- 大学英语四级考试冲刺模拟试卷含作文范文
- 高级审计师综合试题考前速记卷(含解析)
- 2026年秋季初中生物开学第一课 新学期学习规划课件
- 人工智能银行风控
- 青少年健身科普认识体质健康对成长发展的意义
- 人工智能辅助保险营销策略
- 2026年自动驾驶高精地图报告
- 2026年共青团入团考试试题附标准答案
- 2026郑州市新初一三科分班摸底卷摸底卷
- 2026年渭南市大荔县数学三下期末统考模拟试题含答案
- (2026年)痔疮的诊断和治疗健康宣教课件
- 老年人慢性病管理与护理
- T∕CEA 0051-2026 电梯对重块和配重块
- (2026年)血气分析临床解读课件
- 分布式光伏开发建设导则
- 给水用聚乙烯(pe)管道系统第部分管件
- 2024江苏省招聘社区工作者真题题及答案
- 2025年安徽省信用融资担保集团有限公司招聘17人笔试模拟试题及答案
评论
0/150
提交评论