转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 数据库 >> MySql >> 正文
Jsp,JavaBean,Mysql的连接方法         ★★★★

Jsp,JavaBean,Mysql的连接方法

作者:闵涛 文章来源:闵涛的学习笔记 点击数:2640 更新时间:2009/4/22 20:49:00
;<label>
                                            <input type="reset" name="Submit2" value="重置">
                                  </label></td>
                        </tr>
              </table>
       </form>
  </body>
</html>


5. update.jsp 写入数据库

<%@ page contentType="text/html;charset=GBK" import="java.sql.*"%>
<% request.setCharacterEncoding("GBK"); %>


 <jsp:useBean id="Border" scope="page" class="Border.text" />
<%

Connection conn = null;
conn = Border.getConn() ;

  String tit=request.getParameter("Title");
  String prc=request.getParameter("Price");
 
  Statement stmt = conn.createStatement();
  stmt.executeUpdate("INSERT INTO book (title,price) VALUES (''''"+tit+"'''',''''"+prc+"'''')");
%>


<jsp:forward page="text.jsp" />

6. 提供几个函数:

(1). getConnection
public static Connection getConnection(String url,
                                       String user,
                                       String password)
                                throws SQLException
Attempts to establish a connection to the given database URL. The DriverManager attempts to select an appropriate driver from the set of registered JDBC drivers.

Parameters:
url - a database url of the form jdbc:subprotocol:subname
user - the database user on whose behalf the connection is being made
password - the user''''s password
Returns:
a connection to the URL
Throws:
SQLException - if a database access error occurs

(2). createStatement
public Statement createStatement()
                          throws SQLException
Creates a Statement object for sending SQL statements to the database. SQL statements without parameters are normally executed using Statement objects. If the same SQL statement is executed many times, it may be more efficient to use a PreparedStatement object.
Result sets created using the returned Statement object will by default be type TYPE_FORWARD_ONLY and have a concurrency level of CONCUR_READ_ONLY.


Returns:
a new default Statement object
Throws:
SQLException - if a database access error occurs

(3). executeQuery
public ResultSet executeQuery(String sql)
                       throws SQLException
Executes the given SQL statement, which returns a single ResultSet object.

Parameters:
sql - an SQL statement to be sent to the database, typically a static SQL SELECT statement
Returns:
a ResultSet object that contains the data produced by the given query; never null
Throws:
SQLException - if a database access error occurs or the given SQL statement produces anything other than a single ResultSet object

(4). getString
public String getString(String columnName)
                 throws SQLException
Retrieves the value of the designated column in the current row of this ResultSet object as a String in the Java programming language.

Parameters:
columnName - the SQL name of the column
Returns:
the column value; if the value is SQL NULL, the value returned is null
Throws:
SQLException - if a database access error occurs

(5). next
public boolean next()
             throws SQLException
Moves the cursor down one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on.
If an input stream is open for the current row, a call to the method next will implicitly close it. A ResultSet object''''s warning chain is cleared when a new row is read.


Returns:
true if the new current row is valid; false if there are no more rows
Throws:
SQLException - if a database access error occurs

7. ok! Now game is over~~

8. 若您觉得满意,想转载或收藏这篇文章,我非常感谢,但请您注明作者: border ( border@hacker.cn )

                                 http://blog.csdn.net/border1985

 最后欢迎大家访问  --中国安全信息网-- http://www.hacker.cn/


上一页  [1] [2] 


[Web开发]JSP入门学习经验总结  [Web开发]JSP 2.0下的动态内容缓存分析讲解
[Web开发][JSP] 循序渐进教程  [Web开发]纯 jsp 操作服务器上的文本文件
[Web开发]JSP: 调用servlet 显示图片  [Web开发]Jsp + JavaBean循序渐进教程(二)
[Web开发]Jsp + JavaBean循序渐进教程(三)  [Web开发]Jsp + JavaBean循序渐进教程(四)上
[Web开发]Jsp + JavaBean循序渐进教程(四)下  [Web开发]Jsp + JavaBean循序渐进教程(一)
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Sql Server  · MySql
    · Access  · ORACLE
    · SyBase  · 其他
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台