尊敬的个位,由于从C#的桌面程序转到JAVA的JSP的,不怎么会,谁有做好的JSP网页,比如对数据的增删改查功能,其他的暂时估计也用不到, 有的话给我发下,或者给出连接,谢谢了。再次表示感谢下。
解决方案 »
- jsp如何获取客户端ip地址?
- 网页中那些移动的图片怎么实现?
- 如何实现从后台实现自动登陆页面
- 20分: 为什么 <% response.sendRedirect(b);%> 执行,而 onLoad="hh()"> 不执行
- 有没有人懂怎么控制网页上的文字间的行距和间距丫?类似word写字板里面的那些功能?
- JSON格式的String 怎么转成 net.sf.json.JSONObject
- 请大家帮忙了,关于getParameterValues()获得的值写入数据库的问题 ,郁闷ING。。。
- 如何在进入页面时打开个msgbox 谢谢
- 高分求救 分页问题,肯定结帐
- 使用EGit时的疑问
- 求高手
- java keyTool生成证书生,如何让自己的工程打开时地址是HTTPS开头
楼主可以参考下
最好是有个完整的例子,比如解决方案,我自己打开慢慢的看。比如说具体的代码 访问数据库的 我想和C#的差不多,我就是想找个完整的例子。
// user 添加修改
public static boolean updateUser(int userID, String username,
String password, String sex, String email, String qq, String phone) {
/*
* update user information
*/
Connection conn = null;
boolean flag = false;
try {
conn = DB.getConnection();
PreparedStatement ptmt = conn
.prepareStatement("update user "
+ "set username=?, password=?, sex=?, email=?, qq=?, phone=?"
+ " where userID=?");
ptmt.setString(1, username);
ptmt.setString(2, password);
ptmt.setString(3, sex);
ptmt.setString(4, email);
ptmt.setString(5, qq);
ptmt.setString(6, phone);
ptmt.setInt(7, userID);
ptmt.executeUpdate();
flag = true;
} catch (Exception e) {
flag = false;
e.printStackTrace();
} finally {
DB.closeConnection(conn);
}
return flag;
}
//user删除
public static boolean deleteUser(int userID) {
boolean flag = false;
Connection conn = null;
try {
conn = DB.getConnection();
PreparedStatement ptmt = conn
.prepareStatement("delete from user where userID = ?");
ptmt.setInt(1, userID);
ptmt.executeUpdate();
ptmt.close();
ptmt = conn.prepareStatement("delete from reply where userID = ?");
ptmt.setInt(1, userID);
ptmt.executeUpdate();
ptmt.close();
ptmt = conn.prepareStatement("delete from user where userID = ?");
ptmt.setInt(1, userID);
ptmt.executeUpdate();
flag = true;
} catch (Exception e) {
flag = false;
e.printStackTrace();
} finally {
DB.closeConnection(conn);
}
return flag;
}
//DB 类
package com.db;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;public class DB { public static Connection getConnection() {
Connection conn = null;
try {
String driver = "com.mysql.jdbc.Driver";
String dbURL = "jdbc:mysql://localhost:3306/dbName?useUnicode=true&characterEncoding=UTF-8";
String username = "root";
String password = ""; Class.forName(driver).newInstance();
conn = DriverManager.getConnection(dbURL, username, password);
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return conn;
} public static void closeConnection(Connection conn) {
try {
conn.close();
} catch (SQLException e) {
// TODO: handle exception
e.printStackTrace();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}}