⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sortcondb.java~3~

📁 用java实现的一个应用程序,源码非常完整,可以直接运行
💻 JAVA~3~
字号:
package 毕业设计;
import java.sql.*;
import javax.swing.JOptionPane;
import java.util.Vector;
public class SortConDB {
    private Connection con;
    private Statement st;
    private ResultSet rs;
    private PreparedStatement pst;
    public SortConDB()
    {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        } catch (ClassNotFoundException ex) {
            System.out.println("Driver 出错");
        }
        try {
             String url = "jdbc:odbc:lib";
             con = DriverManager.getConnection(url);
             st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                                     ResultSet.CONCUR_UPDATABLE);
        } catch (SQLException ex1) {
            System.out.println("lib 出错");
        }
    }

    public void AddSort(String Sort)
    {
        try {
            String strSQL = "insert Sort values ( '" + Sort +"')";
            pst = con.prepareStatement(strSQL);
            pst.executeUpdate();
            pst.close();
        } catch (SQLException ex) {
        }
    }

    public Vector SearchAll()
    {
        Vector vt = new Vector();
        try {
            String str = "select * from Sort";
            rs = st.executeQuery(str);
            while (rs.next()) {
                Vector temp = new Vector();
                temp.add(rs.getString(1));
                temp.add(rs.getString(2));
                vt.add(temp);
            }
            rs.close();
       } catch (SQLException ex) {
       }
       return vt;
   }

   public Vector SearchSort(String Sort)
   {
       Vector vt = new Vector();
       try {
           String str = "select * from Sort where SortName like '%" +
                        Sort + "%'";
           rs = st.executeQuery(str);
           while (rs.next()) {
               Vector temp = new Vector();
               temp.add(rs.getString(1));
               temp.add(rs.getString(2));
               vt.add(temp);
           }
           rs.close();
      } catch (SQLException ex) {
      }
       return vt;
   }

   public void UpdateSort(int Id, String SortName)
   {
    try {
        String strSQL = "update Sort set SortName = '" + SortName +
                        "' where Id = " + Id ;
        pst = con.prepareStatement(strSQL);
        pst.executeUpdate();
        pst.close();
    } catch (SQLException ex) {
    }
   }

   public void DeleteSort(int Id)
   {
       try {
           String strSQL = "delete from Sort where Id = " + Id ;
           pst = con.prepareStatement(strSQL);
           pst.executeUpdate();
           pst.close();
       } catch (SQLException ex) {
       }
   }

   public void CloseSortDB()
   {
       try {
           st.close();
           con.close();
       } catch (SQLException ex) {
       }
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -