急求如何把页面上输入的长度不超过10的字符串存储到数据库表中?
把页面上输入的长度不超过10的字符串存储到数据库表中存储完成后显示成功提示采用J2ee或jsp完成,数据库可以是MySQL或Oracle...
把页面上输入的长度不超过10的字符串存储到数据库表中
存储完成后显示成功提示
采用J2ee或jsp完成,数据库可以是MySQL或Oracle 展开
存储完成后显示成功提示
采用J2ee或jsp完成,数据库可以是MySQL或Oracle 展开
2个回答
展开全部
例如有表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();// 打印异常,以便修改
}}
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();// 打印异常,以便修改
}}
2011-06-27
展开全部
用取得变量参数的方式得到值,然后拼装 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);
}
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);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询