String language=request.getParameter("language");
用sql语句插入

解决方案 »

  1.   

    <%@ page import="java.sql.*" %>
    <html>
    <head>
    <title>Insert a News</title>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8">
    <link rel="stylesheet" href="newscss.css">
    </head>
    <body><% 
    // get the form value
        String  news_title=request.getParameter("newstitle").trim();
      %>
    <table width=100% >
    <tr><td>
       <%
       try {
    //变量声明
    java.sql.Connection sqlCon; //数据库连接对象
    java.sql.Statement sqlStmt; //SQL语句对象
    java.sql.ResultSet sqlRst; //结果集对象java.lang.String strCon; //数据库连接字符串
    java.lang.String strSQL; //SQL语句//装载JDBC驱动程序
    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
    //设置数据库连接字符串
    strCon = "jdbc:oracle:thin:@localhost:1521:i2";
    //连接数据库
    sqlCon = java.sql.DriverManager.getConnection(strCon,"v6_content2","vignette");
    if (sqlCon!=null) {
    //创建一个SQL语句对象
    sqlStmt = sqlCon.createStatement();
    strSQL="insert into news values ('"+news_title+"')";
    sqlStmt.execute(strSQL);
    out.print ("A News added Successfully<br>");
    %>
    <a href="javascript:history.go(-1)">返回</a>
    </td></tr>
    </table>
    <%
    //关闭SQL语句对象
    sqlStmt.close();
    //关闭数据库
    sqlCon.close();
    } else {
        out.print("Sorry. Database is not available.");
      }
    } catch (Exception e) {
      out.print("Exception: " + e);
    }
    %>
    </body>
    </html>