实体类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;
}实在写补到了 急人啊!!!
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;
}实在写补到了 急人啊!!!
解决方案 »
- java调试的问题,怎样找这行代码上面的内容?
- linux中启动weblogic的命令是什么?
- 请问Hibernate怎么实现MYSQL的这个函数
- 重装了ie后无法打开localhost
- 求教heriterx配置及其应用问题
- javax.ejb包在那里?
- 我要疯了(weblogic的使用)
- 如何启动 J2EE
- ejbcreate的时候出现out of memory exception
- 我是初学习者,请问用cmp的方式做ejb,是不每个表到要生成一个entiybean,另外用cmp做项目好还是bmp呢?
- 断点调试,到断点时怎么防止跳到debug编辑窗口。
- myeclipse8.6中安装groovy插件
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;
}
}
}
以前写过的一个工具类方法 看看可以参考下不
{
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();
}
}
}
}