准备工作:
(1)创建并使用数据库:create database student; use test;
(2)创建表:create table ppp(sno char(7),sname char(8));
(3)插入一条数据:insert into ppp values(123,456);
(4)显示数据:select*from ppp;(复习一下数据库知识)
开始:
(1)打开Myeclipse. 新建web project.(Mysql) 并在WebRoot建立一个Second.jsp
(2)在index.jsp中填写入代码:
     <body>
    <form action="Second.jsp",method="get">
         用户名:<input type="text" name="name"/>
         密    码:<input type="text" name="password"/>
         <input type="submit" value="注册"/>
    </form>
  </body>
(3)在Second.jsp中填写如下代码:
 <body>
 <%
  Connection conn = null ;
   String driver="com.mysql.jdbc.Driver";//数据库驱动
   String userName="root";//数据库用户名
   String userPassword="123";//数据库密码
   String dbName="student";//数据库名
   String tableName="ppp";//表名
   String url = "jdbc:mysql://localhost/" + dbName + "?user=" + userName + "&password=" + userPassword;
   Class.forName("com.mysql.jdbc.Driver").newInstance();  
   conn = DriverManager.getConnection(url);
   String  name=request.getParameter("name");//获取表单数据
   String   password=request.getParameter("password");
   out.println(name);//测试表单数据是否传出来
    Statement stmt = conn.createStatement(); 
    stmt.executeQuery("SET NAMES UTF8"); 
    String sql = "insert into ppp values(‘"+name+"‘,‘"+password+"‘)";
      try{
           stmt.execute(sql);
        }
      catch(Exception e){ }
stmt.close();  
conn.close();  
  %>
</body>
(4)程序流程图:
输入数据:444    555
Second.jsp显示:
数据库显示:
(5)如图:444 555已经加入到数据库了。只有基础学好了,才能学习更好的。不然你怎么知道那个更好,的有比较
原文:http://blog.csdn.net/sky_sea_desert_me/article/details/51333787