个人帐目管理系统java_Java 项目 个人帐目管理系统

本文档描述了一个使用Java开发的个人账目管理系统,包括账目添加、修改、删除和查询功能。系统采用Oracle数据库,实现了数据表设计、序列、触发器、视图和存储过程。业务层和展示层分别通过Swing界面与数据库操作交互,提供了用户友好的操作体验。
摘要由CSDN通过智能技术生成

目录

第一部分项目描述 3

1.1项目目的 3

第二部分需求和开发环境 3

2.1使用技术和开发环境 3

2.2项目需求 3

2.3详细功能 3

2.4 E-R图 3

2.5数据库的设计 3

2.5.1数据表的设计 3

2.5.2数据库约束的设计 4

2.5.3数据库序列的设计 4

2.5.4数据库索引的设计 4

2.5.5数据库视图的设计 5

2.5.6数据库触发器的设计 5

2.5.7数据库函数的设计 5

2.5.8数据库存储过程的设计 6

2.6业务层设计 6

2.6.1 xx业务 6

2.6.2 xx业务 6

2.6.3 xx业务 6

2.7展示层(界面)设计

6

2.7.1 xx界面 7

2.7.2 xx界面 7

2.7.3 xx界面 7

第三部分项目总结 7

第一部分项目描述

1.1项目目的

开发一个账目明细管理软件,用于记录和查询个人的账目情况,记录的内容包括:账目类型(支出/收入)、账目金额、记录日期(日期格式为:yyyy-MM-dd)和备注信息。

第二部分需求和开发环境

2.1使用技术和开发环境

Oracle11g

2.2项目需求

教学质量是学校生存与发展的生命线,不断提高课堂教学水平是学校和每一位教师的共同心愿。及时了解课堂教学的主体—学生对教学情况的评价及建议,有利于教师发现自己教学中的优点以及不足,从而进一步改进教学方法,提高教学水平。为了更好的提高教学水平,建立学校与学员的更好勾通,院领导研究决定研发本系统,并提供考核内容管理、反馈项目管理、反馈表管理、数据统计分析等主要功能,本阶段案例主要以考核内容管理为主要分析目标。

2.3详细功能

1、添加账目

添加账目时,首先,系统自动生成一个账目流水编号,如果为第一条账目记录,则编号为预设值“1”;如果不是第一条记录,则获取最后一条账目记录,取出编号并加一,即为新账目记录编号。然后需要用户输入账目信息,包括账目类型、金额、日期和备注,其中日期为系统自动生成,完成后账目信息被保存到一个文件中,并反馈给用户一条账目信息。

2、修改账目

账目记录修改功能描述:首先,提示用户输入要修改的账目记录编号,并进行有效性验证。然后显示此笔账目记录详细信息,提示修改(日期不修改)。修改完成后,将此账目记录保存到账目记录文件中。

3、删除账目

账目记录删除功能描述:首先,提示用户输入要修改的账目记录编号,并进行有效性验证。然后显示此笔账目记录详细信息,提示删除。待用户确认后,将此记录从账目记录文件中删除。

4、查询账目

查询账目功能包括:查询单个和查询全部。

查询单个账目信息:首先,提示用户输入要修改的账目记录编号,并进行有效性验证。然后显示此笔账目记录详细信息。

查询全部账目信息:显示全部账目记录详细信息,如果没有账目信息,则提示没有账目记录。

2.5数据库的设计

2.5.1 数据表的设计

表1 个人账目表

表名

TALLY(个人账目表)

列名

描述

数据类型

空/非空

约束条件

TID

ID编号

number

非空

主键,标识列

TTYPE

类型名称

Varchar2(20)

非空

MONEY

金钱

Number(4)

非空

DATE

时间

date

默认

REMARK

备注

Varchar2(20)

2.5.3 数据库序列的设计

功能:TID进行插入自增

实现:CREATE SEQUENCE SEQ_TALLY;

2.5.6数据库触发器的设计

功能:当进行插入数据的时候,TID进行自增

实现:CREATE OR REPLACE TRIGGER TRI_TALLY

BEFORE INSERT OR UPDATE  ON TALLY FOR EACH ROW

BEGIN

select seq_tally.nextval into :New."tid" from dual;

END;

2.6

业务层设计

//数据库操作

package com.handson.entity;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.Scanner;

import javax.swing.JOptionPane;

import com.tcl.util.DBcon;

public class DBinsert {

public static void Register(String Itype,String Imoney,String Iremark){

DBcon dBcon=new DBcon();

Connection conn=dBcon.getConn();

if(conn != null){

try {

Statement sm = conn.createStatement();//根据连接获取一个执行sql语句的对象

int n = sm.executeUpdate("insert into TALLY (TTYPE,MONEY,REMARK) VALUES('"+Itype+"','"+Imoney+"','"+Iremark+"')");

if(n>0){

JOptionPane.showMessageDialog(null, "数据添加成功!");

}

else{

JOptionPane.showMessageDialog(null, "数据添加失败!");

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

//Swing 界面package com.handson.services;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.Connection;

import javax.swing.Box;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JTextField;

import com.handson.entity.DBinsert;

import com.tcl.util.DBcon;

public class SWinsert extends JFrame{

JTextField type = new JTextField(10);//文本框

JTextField money = new JTextField(10);

JTextField remark = new JTextField(10);

String Itype,Imoney,Iremark;

Box baseBox,boxV1,boxV2;//面板

JButton btn1 = new JButton("OK");

public SWinsert(){

this.setBounds(100,100,310,260);//窗体大小

this.setTitle("ADD");

this.setLayout(new java.awt.FlowLayout());

init();

this.setVisible(true);

this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);//只关闭当前窗口

}

void init(){

boxV1 = Box.createVerticalBox();

boxV1.add(new JLabel("TYPE:"));

boxV1.add(Box.createVerticalStrut(8));

boxV1.add(new JLabel("MONEY:"));

boxV1.add(Box.createVerticalStrut(8));

boxV1.add(new JLabel("REMARK:"));

boxV1.add(Box.createVerticalStrut(8));

boxV2 = Box.createVerticalBox();

boxV2.add(type);

boxV2.add(Box.createVerticalStrut(8));

boxV2.add(money);

boxV2.add(Box.createVerticalStrut(8));

boxV2.add(remark);

boxV2.add(Box.createVerticalStrut(8));

baseBox = Box.createHorizontalBox();

baseBox.add(boxV1);

boxV2.add(Box.createVerticalStrut(10));

baseBox.add(boxV2);

add(baseBox);

add(btn1);

btn1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

Itype = type.getText();

Imoney = money.getText();

Iremark = remark.getText();

//判断是否为空,因为不能插入空数据

if(!Itype.equals("")&&!Imoney.equals("")&&!Iremark.equals(""))

{

try {

Integer.parseInt(Imoney); // 只能为正整数

DBcon dBcon=new DBcon();

Connection con=dBcon.getConn();

if(con==null){

System.out.println("数据库插入连接失败");

}

else{

System.out.println("数据库插入连接成功");

DBinsert.Register(Itype,Imoney,Iremark);

type.setText("");

money.setText("");

remark.setText("");

}

} catch (Exception e2) {

// TODO: handle exception

JOptionPane.showMessageDialog(null, "Money格式不正确,请重新输入!");

money.setText("");

}

}

else{

JOptionPane.showMessageDialog(null, "数据不能为空,请补充完整!");

}}

});

}

}

2.6.2修改账目业务

//Swing 界面package com.handson.services;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.Connection;

import javax.swing.Box;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JTextField;

import com.handson.entity.DBupdate;

import com.tcl.util.DBcon;

public class SWupdate extends JFrame{

JTextField id = new JTextField(10);

JTextField type = new JTextField(10);

JTextField money = new JTextField(10);

JTextField remark = new JTextField(10);

String Uid,Utype,Umoney,Uremark;

Box baseBox,boxV1,boxV2;

JButton btn1 = new JButton("OK");

public SWupdate(){

this.setBounds(100,100,310,260);

this.setTitle("UPDATE");

this.setLayout(new java.awt.FlowLayout());

init();

this.setVisible(true);

this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);//只关闭当前窗口

}

void init(){

boxV1 = Box.createVerticalBox();

boxV1.add(new JLabel("ID:"));

boxV1.add(Box.createVerticalStrut(8));

boxV1.add(new JLabel("TYPE:"));

boxV1.add(Box.createVerticalStrut(8));

boxV1.add(new JLabel("MONEY:"));

boxV1.add(Box.createVerticalStrut(8));

boxV1.add(new JLabel("REMARK:"));

boxV1.add(Box.createVerticalStrut(8));

boxV2 = Box.createVerticalBox();

boxV2.add(id);

boxV2.add(Box.createVerticalStrut(8));

boxV2.add(type);

boxV2.add(Box.createVerticalStrut(8));

boxV2.add(money);

boxV2.add(Box.createVerticalStrut(8));

boxV2.add(remark);

boxV2.add(Box.createVerticalStrut(8));

baseBox = Box.createHorizontalBox();

baseBox.add(boxV1);

boxV2.add(Box.createVerticalStrut(10));

baseBox.add(boxV2);

add(baseBox);

add(btn1);//按钮

btn1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

Uid = id.getText();

Utype = type.getText();

Umoney = money.getText();

Uremark = remark.getText();

if (!Uid.equals("")&&!Utype.equals("")&&!Umoney.equals("")&&!Uremark.equals("")) {

try {

Integer.parseInt(Umoney); // 只能为正整数

DBcon dBcon=new DBcon();

Connection con=dBcon.getConn();

if(con==null){

System.out.println("数据库更新连接失败");

}

else{

System.out.println("数据库更新连接成功");

DBupdate.update(Uid,Utype,Umoney,Uremark);

id.setText("");

type.setText("");

money.setText("");

remark.setText("");

}

} catch (Exception e2) {

// TODO: handle exception

JOptionPane.showMessageDialog(null, "Money格式不正确,请重新输入!");

money.setText("");

}

}

else {

JOptionPane.showMessageDialog(null, "数据不能为空,请补充完整!");

}

}

});

}

}

数据库更新操作

package com.handson.entity;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.Scanner;

import javax.swing.JOptionPane;

import com.tcl.util.DBcon;

public class DBupdate {

public static void update(String Uid,String Utype,String Umoney,String Uremark){

DBcon dBcon=new DBcon();

Connection conn=dBcon.getConn();

if(conn != null){

try {

Statement sm = conn.createStatement();

int n = sm.executeUpdate("update TALLY set TTYPE= '" + Utype+ "',MONEY='"+Umoney+

"',REMARK='" + Uremark+ "'where TID='" + Uid+ "'");

if(n>0){

JOptionPane.showMessageDialog(null, "Update Success!");

}

else{

JOptionPane.showMessageDialog(null, "ID信息不符合,请确认后重新输入");

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

2.6.3删除账目业务

Swing 界面

package com.handson.services;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.Connection;

import javax.swing.Box;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JTextField;

import com.handson.entity.DBdelete;

import com.tcl.util.DBcon;

public class SWdelete extends JFrame{

JTextField id = new JTextField(10);

String Did;

Box baseBox,boxV1,boxV2;//面板

JButton btn1 = new JButton("OK");

public SWdelete(){

this.setBounds(100,100,310,260);

this.setTitle("DELETE");

this.setLayout(new java.awt.FlowLayout());//容器

init();

this.setVisible(true);

this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);//只关闭当前窗口

}

void init(){

boxV1 = Box.createVerticalBox();

boxV1.add(new JLabel("ID:"));

boxV2 = Box.createVerticalBox();

boxV2.add(id);

baseBox = Box.createHorizontalBox();

baseBox.add(boxV1);

boxV2.add(Box.createVerticalStrut(10));

baseBox.add(boxV2);

add(baseBox);//容器

add(btn1);

btn1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

Did = id.getText();

if (!id.equals("")) {

try {

Integer.parseInt(Did); // 只能为正整数

DBcon dBcon=new DBcon();

Connection con=dBcon.getConn();

if(con==null){

System.out.println("数据库删除连接失败");

}

else{

System.out.println("数据库删除连接成功");

DBdelete.Delete(Did);

id.setText("");

}

} catch (Exception e2) {

// TODO: handle exception

JOptionPane.showMessageDialog(null, "ID格式不正确,请重新输入!");

}

}

else{

JOptionPane.showMessageDialog(null, "数据不能为空,请补充完整!");

}

}

});

}

}

数据库删除操作

package com.handson.entity;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.SQLException;

import javax.swing.JOptionPane;

import com.tcl.util.DBcon;

public class DBdelete {

public static void Delete(String Did){

DBcon dBcon=new DBcon();

Connection conn=dBcon.getConn();

if(conn== null){

dBcon.getConn();

}

PreparedStatement sm = null;//PreparedStatement用于使用绑定变量重用执行计划

try {

String sql = "delete from TALLY where TID = ?";

sm = conn.prepareStatement(sql);

sm.setString(1, Did);//给第一个问号赋值

int n = sm.executeUpdate();

if(n>0){

JOptionPane.showMessageDialog(null, "Delete Success!");

}

else{

JOptionPane.showMessageDialog(null, "请输入正确的ID!");

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

2.6.4查询账目业务

查询单个账目信息:

Swing 界面

package com.handson.services;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.Connection;

import javax.swing.Box;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JTextField;

import com.handson.entity.DBselect;

import com.tcl.util.DBcon;

public class SWselect extends JFrame{

JTextField id = new JTextField(10);//要查询的卡号

JTextField type = new JTextField(10);

JTextField money = new JTextField(10);

JTextField date = new JTextField(10);

JTextField remark = new JTextField(10);

JLabel cxjg = new JLabel();//显示结果标签

Box baseBox,boxV1,boxV2;

JButton btn1 = new JButton("查询");

public SWselect(){

this.setBounds(100,100,310,260);

this.setTitle("查询账目");

this.setLayout(new java.awt.FlowLayout());

init();

this.setVisible(true);

this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);//只关闭当前窗口

}

void init(){

boxV1 = Box.createVerticalBox();

boxV1.add(new JLabel("请输入要查询的ID:"));

boxV1.add(Box.createVerticalStrut(8));

boxV1.add(new JLabel("结果如下:"));

boxV1.add(Box.createVerticalStrut(8));

boxV1.add(new JLabel("TYPE:"));

boxV1.add(Box.createVerticalStrut(8));

boxV1.add(new JLabel("MONEY:"));

boxV1.add(Box.createVerticalStrut(8));

boxV1.add(new JLabel("DATE:"));

boxV1.add(Box.createVerticalStrut(8));

boxV1.add(new JLabel("REMARK:"));

boxV1.add(Box.createVerticalStrut(8));

boxV2 = Box.createVerticalBox();

boxV2.add(id);

boxV2.add(Box.createVerticalStrut(8));

boxV2.add(btn1);

type.setEnabled(false);

boxV2.add(type);

boxV2.add(Box.createVerticalStrut(8));

money.setEnabled(false);

boxV2.add(money);

boxV2.add(Box.createVerticalStrut(8));

date.setEnabled(false);

boxV2.add(date);

boxV2.add(Box.createVerticalStrut(8));

remark.setEnabled(false);

boxV2.add(remark);

boxV2.add(Box.createVerticalStrut(8));

baseBox = Box.createHorizontalBox();

baseBox.add(boxV1);

boxV2.add(Box.createVerticalStrut(10));

baseBox.add(boxV2);

add(baseBox);

btn1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

DBcon dBcon=new DBcon();

Connection con=dBcon.getConn();

if(con==null){

System.out.println("数据库查询连接失败");

}

else{

System.out.println("数据库查询连接成功");

String idString=id.getText();

if (!idString.equals("")) {

try {

Integer.parseInt(idString); // 只能为正整数

DBselect.select(idString);

} catch (Exception e2) {

// TODO: handle exception

JOptionPane.showMessageDialog(null, "ID格式不正确,请重新输入!");

}

}

else {

JOptionPane.showMessageDialog(null, "Please input ID!");

}

//id.setText(DBselect.s);

type.setText(DBselect.Stype);

money.setText(DBselect.Smoney);

date.setText(DBselect.Sdate);

remark.setText(DBselect.Sremark);

}

}

});

}

}数据库查询操作:

package com.handson.entity;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.ResultSetMetaData;

import java.sql.SQLException;

import java.sql.Statement;

import java.util.Scanner;

import javax.swing.JOptionPane;

import com.tcl.util.DBcon;

public class DBselect{

public static String Stype;

public static String Smoney;

public static String Sdate;

public static String Sremark;

public static void select(String idString){

int i=0;

DBcon dBcon=new DBcon();

Connection conn=dBcon.getConn();

if(conn != null){

try {

Statement sm = conn.createStatement();

ResultSet n = sm.executeQuery("select * from TALLY where TID='"+idString+"'");

while (n.next()) {

Stype=n.getString(2);

Smoney=n.getString(3);

Sdate=n.getString(4);

Sremark=n.getString(5);

i++;

// JOptionPane.showMessageDialog(null, "Select Success!");

}

n.close();

sm.close();

conn.close();

if (i==1) {

JOptionPane.showMessageDialog(null, "Select Success!");

}

else {

JOptionPane.showMessageDialog(null, "请输入正确的ID!");

}

}

catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

查询全部账目信息:

package com.handson.entity;

import java.sql.Connection;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import javax.swing.Box;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JTextField;

import com.tcl.util.DBcon;

public class DBSWseleteall extends JFrame{

JTextField id = new JTextField(10);//要查询的卡号

Box baseBox,boxV1,boxV2;

public DBSWseleteall(){

this.setBounds(100,100,450,260);

this.setTitle("查询全部");

this.setLayout(new java.awt.FlowLayout());

init();

this.setVisible(true);

this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);//只关闭当前窗口

}

void init(){

boxV1 = Box.createVerticalBox();

boxV1.add(new JLabel("查询结果如下:"));

boxV1.add(Box.createVerticalStrut(8));

DBcon drop=new DBcon();

Connection conn=drop.getConn();

if(conn != null){

try {

Statement sm = conn.createStatement();

ResultSet n = sm.executeQuery("select * from TALLY");//用于产生单个结果集的语句

while (n.next()) {

String id=n.getString(1);

String type=n.getString(2);

String money=n.getString(3);

String date=n.getString(4);

String remark=n.getString(5);

boxV1.add(new JLabel("ID:"+id+","+"TYPE:"+type+","+"MONEY:"+money+","+"DATE:"+date+","+"REMARK:"+remark+","));

boxV1.add(Box.createVerticalStrut(8));

}

n.close();

sm.close();

conn.close();

}

catch (SQLException i) {

// TODO Auto-generated catch block

i.printStackTrace();

}

}

baseBox = Box.createHorizontalBox();

baseBox.add(boxV1);

add(baseBox);

}

}

运行结果太多就不一一列举了

附主运行界面:

package com.handson.main;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.border.EmptyBorder;

import com.handson.entity.DBSWseleteall;

import com.handson.services.SWdelete;

import com.handson.services.SWinsert;

import com.handson.services.SWselect;

import com.handson.services.SWupdate;

import java.awt.Color;

import java.awt.Font;

import javax.swing.JButton;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

public class Pinit extends JFrame{ //界面的初始化和数据库连接

JButton jb1=null;

public static void main(String[] args)

{

Pinit frame = new Pinit();

frame.setVisible(true);

}

public Pinit()

{

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setBounds(100, 100, 573, 381);

JPanel contentPane = new JPanel();

contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

setContentPane(contentPane);

getContentPane().setBackground(Color.gray);

contentPane.setLayout(null);

JButton tianjia = new JButton("INSERT");

tianjia.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

SWinsert ins = new SWinsert();

}

});

tianjia.setFont(new Font("宋体", Font.PLAIN, 18));

tianjia.setBounds(91, 100, 150, 27);

contentPane.add(tianjia);

JButton xiugai = new JButton("UPDATE");

xiugai.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

SWupdate up = new SWupdate();

}

});

xiugai.setFont(new Font("宋体", Font.PLAIN, 18));

xiugai.setBounds(91, 150, 150, 27);

contentPane.add(xiugai);

JButton shanchu= new JButton("DELETE");

shanchu.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

SWdelete dr = new SWdelete();

}

});

shanchu.setFont(new Font("宋体", Font.PLAIN, 18));

shanchu.setBounds(91, 200, 150, 27);

contentPane.add(shanchu);

JButton zhangmu = new JButton("SELECT");

zhangmu.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

SWselect se = new SWselect();

}

});

zhangmu.setFont(new Font("宋体", Font.PLAIN, 18));

zhangmu.setBounds(300,100, 150, 27);

contentPane.add(zhangmu);

JButton quanbu = new JButton("SELECT ALL");

quanbu.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

DBSWseleteall se = new DBSWseleteall();

}

});

quanbu.setFont(new Font("宋体", Font.PLAIN, 18));

quanbu.setBounds(300,150, 150, 27);

contentPane.add(quanbu);

JButton tuichu = new JButton("EXIT");

tuichu.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

System.exit(0);

}

});

tuichu.setFont(new Font("宋体", Font.PLAIN, 18));

tuichu.setBounds(300,200, 150, 27);

contentPane.add(tuichu);

// 连接数据库 测试

String URL = "jdbc:oracle:thin:@localhost:1521:ORCL";

String user = "scott";//sql用户名

String psd = "123456";//sql密码

try

{

Class.forName("oracle.jdbc.driver.OracleDriver");

Connection con = DriverManager.getConnection(URL, user, psd);

Statement stat = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,

ResultSet.CONCUR_READ_ONLY);

JOptionPane.showMessageDialog(null, "RUNNING。。。");

}

catch (ClassNotFoundException e)

{

JOptionPane.showMessageDialog(null, "SQL链接不成功!"); //未查找到相应的连接内容

}

catch (SQLException e)

{

JOptionPane.showMessageDialog(null, "FAIL!"); //数据库未连接

}

}

}运行结果:

c6c9ad81480cdaa69d852b37e1901ab3.png

第三部分总结

其中用了大量的Swing界面视图的构建,还有数据库的连接已经进行操作。其中还对各种输入的错误操作进行了错误提醒。就是这样。

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
java语言写的android系统,用于个人账目管理,课程设计上写的欢迎下载 package moneymanager.moneymanager; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; /* * * 데이터베이스를 관리하는 클래스입니다. * */ public class DBAdapter { private static final String TAG = "NotesDbAdapter"; private DatabaseHelper mDbHelper; private SQLiteDatabase mDb; // 데이터베이스이름과 테블이름들을 정의 private static final String DATABASE_NAME = "MoneyManagerDB"; private static final int DATABASE_VERSION = 2; private static final String DATABASE_SETTING_TABLE = "SettingTbl"; private static final String DATABASE_BADGET_TABLE = "BadgetTbl"; private static final String DATABASE_PAYMENT_TABLE = "PaymentTbl"; // 테블안의 항목들을 정의 public static final String KEY_SETTINGTBL_ID = "ID"; public static final String KEY_SETTINGTBL_NAME = "Name"; public static final String KEY_SETTINGTBL_VALUE = "Value"; public static final String KEY_BADGETTBL_ID = "ID"; public static final String KEY_BADGETTBL_ITEM = "Item"; public static final String KEY_BADGETTBL_MONEY = "Money"; public static final String KEY_PAYMENTTBL_ID = "ID"; public static final String KEY_PAYMENTTBL_BADGETID = "BadgetID"; public static final String KEY_PAYMENTTBL_OUTDATE = "OutDate"; public static final String KEY_PAYMENTTBL_MONEY = "Money"; public static final String KEY_PAYMENTTBL_NOTE = "Note"; private final Context mCtx; private static class DatabaseHelper extends SQLiteOpenHelper { DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { String strCreateTbl; // SettingTbl생성 strCreateTbl = "CREATE TABLE " + DATABASE_SETTING_TABLE + " (" + KEY_SETTINGTBL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_SETTINGTBL_NAME + " TEXT NOT NULL, " + KEY_SETTINGTBL_VALUE + " TEXT NOT NULL);"; db.execSQL(strCreateTbl); // BadgetTbl생성 strCreateTbl = "CREATE TABLE " + DATABASE_BADGET_TABLE + " (" + KEY_BADGETTBL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_BADGETTBL_ITEM + " TEXT NOT NULL, " + KEY_BADGETTBL_MONEY + " INTEGER NOT NULL);"; db.execSQL(strCreateTbl); // PaymentTbl생성 strCreateTbl = "CREATE TABLE " + DATABASE_PAYMENT_TABLE + " (" + KEY_PAYMENTTBL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_PAYMENTTBL_BADGETID + " INTEGER NOT NULL, " + KEY_PAYMENTTBL_OUTDATE + " TEXT NOT NULL, " + KEY_PAYMENTTBL_MONEY + " INTEGER NOT NULL, " + KEY_PAYMENTTBL_NOTE + " TEXT);"; db.execSQL(strCreateTbl); } ......
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值