急求如何把页面上输入的长度不超过10的字符串存储到数据库表中?
发布网友
发布时间:2023-09-30 05:28
我来回答
共2个回答
热心网友
时间:2024-08-26 07:40
例如有表demo:create table demo(word varchar2(10)),在jsp中写以下代码:
Connection connection=null;
PreparedStatement statement=null;
ResultSet resultSet=null;
String strWord=request.getParameter("word");//假如文本框的名字是word
String sql="insert into demo values("+strWord+")";
try {
connection=ConnectDB.getConn();
statement=connection.prepareStatement(sql);
int iChangeNum=statement.executeUpdate();
out.print("<span style='green'>插入成功</span>");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
out.print("<span style='red'>插入失败</span>");
}
finally{
try {
if (resultSet != null) {
resultSet.close();
resultSet = null;
}
if (statement != null) {
statement.close();
statement = null;
}
if (connection != null) {
connection.close();
connection = null;
}
} catch (Exception e1) {
e1.printStackTrace();// 打印异常,以便修改
}}
热心网友
时间:2024-08-26 07:41
用取得变量参数的方式得到值,然后拼装 sql statement。
stmt = dbConn.createStatement ();
rset = stmt.executeQuery ("select count(*) from cm_sale_goods "
+"where sgds_id='"+s_sgds_id+"' "
+"and nvl(sgds_status_id,'0')='0'");
while (rset.next ())
{
//将取出的商品数量付给变量
s_amount=rset.getInt(1);
}