这是用Java编写的一个简单的银行转账系统,包括取款,存款,转账等功能,其中用到了数据库的连接,采用Eclipse编写,包含数据库的设计文件。
非常适合有一定基础的Java初学者使用。
packagecom.gujunjia.bank;/**Tochangethistemplate,chooseTools|Templates*andopenthetemplateintheeditor.*/importjava.sql.*;/****@authorgujunjia*/publicclassDataBase{ staticConnectionconn; staticPreparedStatementst; staticResultSetrs; /** *加载驱动 */ publicstaticvoidloadDriver() {  try  {   Class.forName("com.mysql.jdbc.Driver");  }  catch(ClassNotFoundExceptione)  {   System.out.println("加载驱动失败");  } } /** *创建数据库的连接 * *@paramdatabase *需要访问的数据库的名字 */ publicstaticvoidconnectionDatabase(Stringdatabase) {  try  {   Stringurl="jdbc:mysql://localhost:3306/"+database;   Stringusername="root";   Stringpassword="gujunjia";   conn=DriverManager.getConnection(url,username,password);  }  catch(SQLExceptione)  {   System.out.println(e.getMessage());  } } /** *关闭数据库连接 */ publicstaticvoidcloseConnection() {  if(rs!=null)  {//关闭记录集   try   {    rs.close();   }   catch(SQLExceptione)   {    e.printStackTrace();   }  }  if(st!=null)  {//关闭声明   try   {    st.close();   }   catch(SQLExceptione)   {    e.printStackTrace();   }  }  if(conn!=null)  {//关闭连接对象   try   {    conn.close();   }   catch(SQLExceptione)   {    e.printStackTrace();   }  } }}packagecom.gujunjia.bank;/**Tochangethistemplate,chooseTools|Templates*andopenthetemplateintheeditor.*/importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;/***本类次要实现整个系统的界面**@authorgujunjia*/publicclassMainFrameextendsJFrameimplementsActionListener,FocusListener{ /** * */ privatestaticfinallongserialVersionUID=1L; publicstaticStringuserId; JTextFielduserIdText; JPasswordFieldpasswordText; JButtonregisterButton; JButtonlogInButton; publicMainFrame() {  super("个人银行系统
                                    
                                    
                                        
                                            1