实体类package com.entity;public class login {
private int id;
private String name;
private int age;
private String sex;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}}
连接数据库的类package com.db;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;public class DBhpler { private static Connection con() {
Connection con = null;
try {
Class.forName("com.microsoft.sqlserver.jdbc");
con = DriverManager.getConnection(
"jdbc:sqlserver://localhost:1433;databasename=zhdb", "sa",
"zhczqwhy");
} catch (Exception e) {
e.printStackTrace();
}
return con;
} public void closeCon(Connection con) {
if (con != null)
try {
if (!con.isClosed())
con.close();
} catch (Exception e) {
e.printStackTrace();
} }
}
方法不会写了 希望帮忙补充完整 还有页面(最好用el表达式)
package com.dao;import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;public class stuDao {
private static Connection con=null;
private static PreparedStatement ps=null;
private static ResultSet rs=null;

}实在写补到了 急人啊!!!

解决方案 »

  1.   

    //对数据库的增加、修改和删除的操作
      public boolean executeUpdate(String sql) {    if (con == null) {
          creatConnection();
        }
        try {
          Statement stmt = con.createStatement();
          int iCount = stmt.executeUpdate(sql);
          System.out.println("操作成功,所影响的记录数为" + String.valueOf(iCount));
        }
        catch (SQLException e) {
          System.out.println(e.getMessage());
          System.out.println("executeUpdaterError!");
        }
        return true;
      }
    //对数据库的查询操作
      public ResultSet executeQuery(String sql) {
        ResultSet rs;
        try {
          if (con == null) {
            creatConnection();
          }
          Statement stmt = con.createStatement();
          try {
            rs = stmt.executeQuery(sql);
          }
          catch (SQLException e) {
            System.out.println(e.getMessage());
            return null;
          }
        }
        catch (SQLException e) {
          System.out.println(e.getMessage());
          System.out.println("executeQueryError!");
          return null;
        }
        return rs;
      }
    //关闭数据库的操作
      public void closeConnection() {
        if (con != null) {
          try {
            con.close();
          }
          catch (SQLException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
            System.out.println("Failed to close connection!");
          }
          finally {
            con = null;
          }
        }
      }
    以前写过的一个工具类方法 看看可以参考下不
      

  2.   

    public class stuDao
    {
        private static Connection con = DBhpler.getCon();
        
        public void getResultSet()
        {
            
            PreparedStatement ps = null;
            
            ResultSet rs = null;
            
            try
            {
                con.setAutoCommit(false);
                ps = con.prepareStatement("select * from test where id=?");
                ps.setInt(1, 12);
                rs = ps.executeQuery();
            }
            catch (SQLException e)
            {
                try
                {
                    con.rollback();
                }
                catch (SQLException e1)
                {
                    e1.printStackTrace();
                }
                e.printStackTrace();
            }
            finally
            {
                try
                {
                    if (rs.isClosed())
                    {
                        rs.close();
                    }
                    if (ps.isClosed())
                    {
                        ps.close();
                    }
                    if (con.isClosed())
                    {
                        con.close();
                    }
                }
                catch (SQLException e)
                {
                    // TODO Auto-generated catch block 
                    e.printStackTrace();
                }
            }
        }
    }
      

  3.   

    con.setAutoCommit(false); 多余 无用
      

  4.   

    多看几个JDBC DEMO,,就可以设计得更周全了。
      

  5.   

    D:\jdk1.5.0_04\demo\jfc\TableExample\src\JDBCAdapter.java