課程
/后端開發
/Java
/JAVA遇見HTML——Servlet篇
怎么用servlet對oracle進行增刪改查???請賜教
2016-03-31
源自:JAVA遇見HTML——Servlet篇 1-1
正在回答
加載驅動2創建連接
public static Connection getConn() throws SQLException,
ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver");//1
return DriverManager
.getConnection(
"jdbc:mysql://localhost:3306/bookstore?useUnicode=true&characterEncoding=utf-8",
"root", "password");//2
}
3執行語句
String sql = "select authorise from user where username=? and password = ?";
pst=con.prepareStatement(sql);
pst.setString(1, name);
pst.setString(2, password);
rs = pst.executeQuery();//查詢用這條
String sql="update book set bookname=?,price=? where id=?";
pst.setString(1, book.getBookname());
pst.setFloat(2, book.getPrice());
pst.setInt(3,book.getId());
count=pst.executeUpdate();//增刪改用這條
4得到結果
while(rs.next()!=null){}
5關閉連接
if (rs != null) {
rs.close();
if (pst != null) {
pst.close();
if (con != null) {
con.close();
顛覆IT 提問者
是對oracle的操作而不是mysql,具體代碼能寫一下嗎?謝謝
不需要jsp跳轉嗎?經理要求不用jsp 可我沒試過
舉報
本門課程在JSP課程的基礎上,深入介紹Servlet的基礎知識
1 回答增刪改查的
5 回答對于servlet的問題-.-
4 回答servlet執行過程
1 回答刪除路徑是否加servlet的問題
2 回答servlet修改后部署問題
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-03-31
加載驅動2創建連接
public static Connection getConn() throws SQLException,
ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver");//1
return DriverManager
.getConnection(
"jdbc:mysql://localhost:3306/bookstore?useUnicode=true&characterEncoding=utf-8",
"root", "password");//2
}
3執行語句
String sql = "select authorise from user where username=? and password = ?";
pst=con.prepareStatement(sql);
pst.setString(1, name);
pst.setString(2, password);
rs = pst.executeQuery();//查詢用這條
String sql="update book set bookname=?,price=? where id=?";
pst=con.prepareStatement(sql);
pst.setString(1, book.getBookname());
pst.setFloat(2, book.getPrice());
pst.setInt(3,book.getId());
count=pst.executeUpdate();//增刪改用這條
4得到結果
while(rs.next()!=null){}
5關閉連接
if (rs != null) {
rs.close();
}
if (pst != null) {
pst.close();
}
if (con != null) {
con.close();
}
2016-04-01
是對oracle的操作而不是mysql,具體代碼能寫一下嗎?謝謝
2016-04-01
不需要jsp跳轉嗎?經理要求不用jsp 可我沒試過