真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

網(wǎng)上書(shū)城java代碼 javaweb書(shū)城項(xiàng)目代碼

javaweb書(shū)城項(xiàng)目 改別人項(xiàng)目遇到的問(wèn)題

明顯是路徑?jīng)]找到,你調(diào)試下程序,在java代碼加下斷點(diǎn),看看有沒(méi)有進(jìn)斷點(diǎn)。

創(chuàng)新互聯(lián)是一家專業(yè)提供融安企業(yè)網(wǎng)站建設(shè),專注與成都做網(wǎng)站、成都網(wǎng)站建設(shè)、H5響應(yīng)式網(wǎng)站、小程序制作等業(yè)務(wù)。10年已為融安眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)的建站公司優(yōu)惠進(jìn)行中。

網(wǎng)上書(shū)店連接SQL Server 2005的java代碼怎么寫(xiě)?

連接數(shù)據(jù)庫(kù)的典型步驟

第一步:加載正確的數(shù)據(jù)庫(kù)驅(qū)動(dòng)程序

第二步,定義所要連接數(shù)據(jù)庫(kù)的地址

String ODBCURL=“jdbc:odbc:dbName”;

String oracleURL= "jdbc:oracle:thin:@host:port:dbName“;

String mysqlURL= "jdbc:mysql:// host:port/dbName“;

String sqlURL=“jdbc:microsoft:sqlserver://host:1433;DatabaseName=dbName”;

第三步,建立與數(shù)據(jù)庫(kù)的連接

DriverManager.getConnection(oracleURL,

username,

password);

第四步,創(chuàng)建語(yǔ)句對(duì)象

Statement statement = connection.createStatement();

第五步,聲明SQL語(yǔ)句,并將該語(yǔ)句通過(guò)Statement對(duì)象提交給服務(wù)器進(jìn)行執(zhí)行。

Stringsql= “SELECT * FROM ONTACT_TABLE”;

ResultSet resultSet=statement.executeQuery(sql);

該語(yǔ)句將sql命令提交給數(shù)據(jù)庫(kù)服務(wù)器進(jìn)行執(zhí)行,并將執(zhí)行結(jié)果存儲(chǔ)在ResultSet對(duì)象中進(jìn)行執(zhí)行。

Statement接口主要有如下三個(gè)方法:

1. ResultSet executeQuery(String sql)

用于執(zhí)行查詢語(yǔ)句,返回 ResultSet結(jié)果集(一個(gè)二維表)

2. int executeUpdate(String sql)

用于執(zhí)行添加、刪除或修改操作,返回被更新記錄的條數(shù)

3. boolean execute(String sql)

執(zhí)行參數(shù)部分的SQL語(yǔ)句;

當(dāng)SQL語(yǔ)句的執(zhí)行結(jié)果是一個(gè)ResultSet結(jié)果集時(shí),本方法返回true;并可以通過(guò)Statement?getResultSet()方法得到返回的結(jié)果集

當(dāng)SQL語(yǔ)句執(zhí)行后沒(méi)有返回的結(jié)果集時(shí),該方法返回false

第六步:對(duì)查詢結(jié)果進(jìn)行分析

while(resultSet.next()){

name =resultSet.getString(1);

phone =resultSet.getString(2);

System.out.println(name+","+phone);

}

第七步,關(guān)閉打開(kāi)的資源

resultSet.close();

statement.close();

connection.close();

將打開(kāi)的資源關(guān)閉。

注意:資源關(guān)閉的順序和打開(kāi)的順序恰恰相反。

某網(wǎng)上書(shū)城可以查詢、刪除書(shū)籍,現(xiàn)要求使用JSP實(shí)現(xiàn)該功能

簡(jiǎn)單的增刪改查功能

package?EBookDao;

import?java.sql.Connection;

import?java.sql.PreparedStatement;

import?java.sql.ResultSet;

import?java.sql.SQLException;

import?java.util.ArrayList;

import?java.util.List;

import?DBUtil.DBUtil;

import?DBUtil.EBook;

/*

*查詢書(shū)集信息

*?

*?*/

public?class?EBookCZ?{

public?ListEBook?find()?{

Connection?conn?=?null;

PreparedStatement?ps?=?null;

ResultSet?rs?=?null;

ListEBook?list?=?new?ArrayListEBook();

try?{

conn?=?DBUtil.getConnection();

String?sql?=?"SELECT?*?FROM?ebook";

ps?=?conn.prepareStatement(sql);

rs?=?ps.executeQuery();

while?(rs.next())?{

EBook?eBook?=?new?EBook();

eBook.setId(rs.getInt("ID"));

eBook.setBname(rs.getString("bname"));

eBook.setPrice(rs.getString("price"));

list.add(eBook);

System.out.println(rs.getInt("ID")+rs.getString("bname")+rs.getString("price"));

}

}?catch?(SQLException?sqle)?{

sqle.printStackTrace();

}?finally?{

DBUtil.close(conn,?ps,?rs);

}

return?list;

}

/*

?*通過(guò)id刪除書(shū)集信息

?*?

?*?*/

public?static?EBook?DelById(int?id)?{

Connection?conn?=?null;

PreparedStatement?ps?=?null;

ResultSet?rs?=?null;

EBook?book?=?null;

try?{

conn?=?DBUtil.getConnection();

String?sql?=?"delete?ebook?";

sql?+=?"WHERE?ID=??";

ps?=?conn.prepareStatement(sql);

ps.setInt(1,?id);

rs?=?ps.executeQuery();

if?(rs.next())?{

book?=?new?EBook();

book.setId(rs.getInt("ID"));

book.setBname(rs.getString("bname"));

book.setPrice(rs.getString("price"));

}

}?catch?(SQLException?sqle)?{

sqle.printStackTrace();

}?finally?{

DBUtil.close(conn,?ps,?rs);

}

return?book;

}

}

package?EBookServlet;

import?java.io.IOException;

import?java.io.PrintWriter;

import?java.util.List;

import?javax.servlet.ServletException;

import?javax.servlet.http.HttpServlet;

import?javax.servlet.http.HttpServletRequest;

import?javax.servlet.http.HttpServletResponse;

import?DBUtil.EBook;

import?EBookDao.EBookCZ;

public?class?EBookServlet?extends?HttpServlet?{

/**

?*?

?*/

private?static?final?long?serialVersionUID?=?1L;

/**

?*?Constructor?of?the?object.

?*/

public?EBookServlet()?{

super();

}

/**

?*?Destruction?of?the?servlet.?br

?*/

public?void?destroy()?{

super.destroy();?//?Just?puts?"destroy"?string?in?log

//?Put?your?code?here

}

/**

?*?The?doGet?method?of?the?servlet.?br

?*?

?*?This?method?is?called?when?a?form?has?its?tag?value?method?equals?to?get.

?*?

?*?@param?request

?*????????????the?request?send?by?the?client?to?the?server

?*?@param?response

?*????????????the?response?send?by?the?server?to?the?client

?*?@throws?ServletException

?*?????????????if?an?error?occurred

?*?@throws?IOException

?*?????????????if?an?error?occurred

?*/

public?void?doGet(HttpServletRequest?request,?HttpServletResponse?response)

throws?ServletException,?IOException?{

this.doPost(request,?response);

}

/**

?*?The?doPost?method?of?the?servlet.?br

?*?

?*?This?method?is?called?when?a?form?has?its?tag?value?method?equals?to

?*?post.

?*?

?*?@param?request

?*????????????the?request?send?by?the?client?to?the?server

?*?@param?response

?*????????????the?response?send?by?the?server?to?the?client

?*?@throws?ServletException

?*?????????????if?an?error?occurred

?*?@throws?IOException

?*?????????????if?an?error?occurred

?*/

public?void?doPost(HttpServletRequest?request,?HttpServletResponse?response)

throws?ServletException,?IOException?{

response.setContentType("text/html;charset=utf-8");

PrintWriter?out?=?response.getWriter();

String?method?=?request.getParameter("method");

String?url?=?"";

EBookCZ?bookCZ=new?EBookCZ();

?if?(method?!=?null??method.equals("find"))?{

?System.out.println("find做完了");

??url?=?"EBookMNG.jsp";

??ListEBook?list?=?bookCZ.find();

??request.setAttribute("list",?list);

}?else?if?(method?!=?null??method.equals("findById"))?{

?System.out.println("findbyid做完了");

??url?=?"OK.jsp";

??int?id?=?Integer.parseInt(request.getParameter("id"));

??EBook?book?=?EBookCZ.DelById(id);

??request.setAttribute("book",?book);

}

request.getRequestDispatcher(url).forward(request,?response);

out.flush();

out.close();

}

/**

?*?Initialization?of?the?servlet.?br

?*?

?*?@throws?ServletException

?*?????????????if?an?error?occurs

?*/

public?void?init()?throws?ServletException?{

//?Put?your?code?here

}

}


分享文章:網(wǎng)上書(shū)城java代碼 javaweb書(shū)城項(xiàng)目代碼
網(wǎng)頁(yè)URL:http://weahome.cn/article/hjhpoc.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部