用JAVA对数据库信息进行增加、删除、修改、查看怎么写谁能帮忙,能的加QQ1505209873我把我写好的代码发给
我写的类行不一样啊我在数据库已经把表什么都建好了在JAVA中去实现JAVA中我做了界面点击出现事件对数据库信息进行增加、删除等是在JAVA中用SQL语句当然JAVA和数据...
我写的类行不一样啊 我在数据库已经把表什么都建好了 在JAVA中去实现 JAVA中我做了界面 点击出现事件 对数据库信息进行增加、删除等 是在JAVA中用SQL语句 当然JAVA和数据库已经连接了 会的我直接把我写了的代码传给他 数据库 JAVA的都可以传 就剩增加、删除和查询了
展开
4个回答
展开全部
这个不是简单的数据库 数据的添加 删除 修改 和查看吗
这个是一个家具买卖页面所涉及的 曾删改查都有了,详细内容看代码
package Dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import Entity.JIAJU;
public class JiaJu {
public JIAJU selectExe(int shouhinId) {
JIAJU jia = new JIAJU();
try {
Connection con = ConnectionManager.getConnection();
String sql = "select * from jiaju where shouhinId=?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1, shouhinId);
ResultSet rs = ps.executeQuery();
if (rs != null) {
while (rs.next()) {
jia.setShouhinId(rs.getInt("shouhinId"));
jia.setShouhinName(rs.getString("shouhinName"));
jia.setShouhinColor(rs.getString("shouhinColor"));
jia.setShouhinPrice(rs.getInt("shouhinPrice"));
jia.setShouhinPai(rs.getString("shouhinPai"));
jia.setShouhinShi(rs.getString("shouhinShi"));
// list.add(jia);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return jia;
}
public void insertJia(JIAJU jia) {
try {
Connection con = ConnectionManager.getConnection();
String sql = "insert into jiaju values(?,?,?,?,?)";
PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1, jia.getShouhinName());
ps.setString(2, jia.getShouhinColor());
ps.setInt(3, jia.getShouhinPrice());
ps.setString(4, jia.getShouhinPai());
ps.setString(5, jia.getShouhinShi());
ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
}
public List selectJia() {
List list = new ArrayList();
try {
Connection con = ConnectionManager.getConnection();
String sql = "select * from jiaju ";
PreparedStatement ps = con.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
if (rs != null) {
while (rs.next()) {
JIAJU jia = new JIAJU();
jia.setShouhinId(rs.getInt("shouhinId"));
jia.setShouhinName(rs.getString("shouhinName"));
jia.setShouhinColor(rs.getString("shouhinColor"));
jia.setShouhinPrice(rs.getInt("shouhinPrice"));
jia.setShouhinPai(rs.getString("shouhinPai"));
jia.setShouhinShi(rs.getString("shouhinShi"));
list.add(jia);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
public JIAJU selectbuy(int shouhinId) {
JIAJU jia = new JIAJU();
try {
Connection con = ConnectionManager.getConnection();
String sql = "select * from jiaju where shouhinId=?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1, shouhinId);
ResultSet rs = ps.executeQuery();
if (rs != null) {
while (rs.next()) {
jia.setShouhinId(rs.getInt("shouhinId"));
jia.setShouhinName(rs.getString("shouhinName"));
jia.setShouhinColor(rs.getString("shouhinColor"));
jia.setShouhinPrice(rs.getInt("shouhinPrice"));
jia.setShouhinPai(rs.getString("shouhinPai"));
jia.setShouhinShi(rs.getString("shouhinShi"));
}
}
} catch (Exception e) {
e.printStackTrace();
}
return jia;
}
public void updateLou(JIAJU jia){
try{
Connection con = ConnectionManager.getConnection();
String sql = "update jiaju set shouhinPrice=? where shouhinId=?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1,jia.getShouhinPrice());
ps.setInt(2, jia.getShouhinId());
ps.executeUpdate();
}catch(Exception e){
e.printStackTrace();
}
}
public void deleteLou(JIAJU jia){
try{
Connection con = ConnectionManager.getConnection();
String sql = "delete from jiaju where shouhinId=?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1, jia.getShouhinId());
ps.executeUpdate();
}catch(Exception e){
e.printStackTrace();
}
}
}
这个是一个家具买卖页面所涉及的 曾删改查都有了,详细内容看代码
package Dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import Entity.JIAJU;
public class JiaJu {
public JIAJU selectExe(int shouhinId) {
JIAJU jia = new JIAJU();
try {
Connection con = ConnectionManager.getConnection();
String sql = "select * from jiaju where shouhinId=?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1, shouhinId);
ResultSet rs = ps.executeQuery();
if (rs != null) {
while (rs.next()) {
jia.setShouhinId(rs.getInt("shouhinId"));
jia.setShouhinName(rs.getString("shouhinName"));
jia.setShouhinColor(rs.getString("shouhinColor"));
jia.setShouhinPrice(rs.getInt("shouhinPrice"));
jia.setShouhinPai(rs.getString("shouhinPai"));
jia.setShouhinShi(rs.getString("shouhinShi"));
// list.add(jia);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return jia;
}
public void insertJia(JIAJU jia) {
try {
Connection con = ConnectionManager.getConnection();
String sql = "insert into jiaju values(?,?,?,?,?)";
PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1, jia.getShouhinName());
ps.setString(2, jia.getShouhinColor());
ps.setInt(3, jia.getShouhinPrice());
ps.setString(4, jia.getShouhinPai());
ps.setString(5, jia.getShouhinShi());
ps.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
}
public List selectJia() {
List list = new ArrayList();
try {
Connection con = ConnectionManager.getConnection();
String sql = "select * from jiaju ";
PreparedStatement ps = con.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
if (rs != null) {
while (rs.next()) {
JIAJU jia = new JIAJU();
jia.setShouhinId(rs.getInt("shouhinId"));
jia.setShouhinName(rs.getString("shouhinName"));
jia.setShouhinColor(rs.getString("shouhinColor"));
jia.setShouhinPrice(rs.getInt("shouhinPrice"));
jia.setShouhinPai(rs.getString("shouhinPai"));
jia.setShouhinShi(rs.getString("shouhinShi"));
list.add(jia);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
public JIAJU selectbuy(int shouhinId) {
JIAJU jia = new JIAJU();
try {
Connection con = ConnectionManager.getConnection();
String sql = "select * from jiaju where shouhinId=?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1, shouhinId);
ResultSet rs = ps.executeQuery();
if (rs != null) {
while (rs.next()) {
jia.setShouhinId(rs.getInt("shouhinId"));
jia.setShouhinName(rs.getString("shouhinName"));
jia.setShouhinColor(rs.getString("shouhinColor"));
jia.setShouhinPrice(rs.getInt("shouhinPrice"));
jia.setShouhinPai(rs.getString("shouhinPai"));
jia.setShouhinShi(rs.getString("shouhinShi"));
}
}
} catch (Exception e) {
e.printStackTrace();
}
return jia;
}
public void updateLou(JIAJU jia){
try{
Connection con = ConnectionManager.getConnection();
String sql = "update jiaju set shouhinPrice=? where shouhinId=?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1,jia.getShouhinPrice());
ps.setInt(2, jia.getShouhinId());
ps.executeUpdate();
}catch(Exception e){
e.printStackTrace();
}
}
public void deleteLou(JIAJU jia){
try{
Connection con = ConnectionManager.getConnection();
String sql = "delete from jiaju where shouhinId=?";
PreparedStatement ps = con.prepareStatement(sql);
ps.setInt(1, jia.getShouhinId());
ps.executeUpdate();
}catch(Exception e){
e.printStackTrace();
}
}
}
展开全部
1.Connection
2.预处理
3.resultset
4.你想干啥干啥
5.顺序释放资源。。。你也可以不释放。。。。
建议:写一个类统一管理
2.预处理
3.resultset
4.你想干啥干啥
5.顺序释放资源。。。你也可以不释放。。。。
建议:写一个类统一管理
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Hibernate,
多好的东西, 透明持久化, 侵入性小, 轻量.
多好的东西, 透明持久化, 侵入性小, 轻量.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
问题解决了吗?如果有需要,你可以直接找我
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询