我这个sql语句在哪里输入哪里有错误呢?

我在调用存储过程的同时,运用了回滚,但是当sql语句有错误时,没回滚,不知错在哪里?
我在调用存储过程的同时,运用了回滚,但是当sql语句有错误时,没回滚,不知错在哪里?
下面的程序在运行的时候,当有一条sql语句出现错误,程序并没有回滚,不知道是为什么?我去查看sqlserver2000数据库表,发现正确的sql语句记录是插进了数据库表。在程序的开始我也设置了“conn.setAutoCommit(false);”并且程序也应该执行到了“conn.rollback();”这个地方来了,因为它上面的一条输出语句语句“System.out.println("应该执行了回滚!");”是执行了。总的来说我就是不知道为什么出了错,没有进行回滚?请帮忙解决!
public int[] callProcedureBatch(Vector allScore) {
DbConnection connection=new DbConnection();
conn=connection.getConnection();
CallableStatement stmt=
int []counts=
int allScoreCount=allScore.size();
conn.setAutoCommit(false);
for(int i=0;i&allScoreCi++)
Vector v=new Vector();
v=(Vector)allScore.elementAt(i);
int columnCount=v.size();
stmt = conn.prepareCall("{call inputStudentScore(?, ?, ?, ?,?,?,?)}");
for(int j=0;j&columnCj++)
stmt.setString(j+1, String.valueOf(v.elementAt(j)).trim());
stmt.setObject(j+1, v.elementAt(j));
stmt.addBatch();
counts=stmt.executeBatch();
conn.setAutoCommit(true);
catch(SQLException e)
e.printStackTrace();
if(conn!=null)
System.out.println("应该执行了回滚!");
conn.rollback();
conn.setAutoCommit(true);
} catch (SQLException e1) {
e1.printStackTrace();
catch(Exception e)试试~
1、为什么要在调用该 callProcedureBatch(Vector allScore)函数的InputStudentScan.java中设置捕获异常?该函数本身内部我已经做了捕获,为什么不起到可以让程回滚?
2、为什么try{}catch(Exception e1){e1.printStackTrace()}要将最外层的for(){for(){}}包起来?
3、既然程序已经执行了回滚,那么就说明sql语句有错,但是正确的sql语句记录却照常插进了,并没有达到我想要的,只要sql一出错,就回滚到起始状态,不据库进行任何更改。
请帮帮忙,解释一下,非常感谢!
下面是InputStudentScore.java中调用函数"callProcedureBatch(Vector allScore)"的部分代码!
for(int i=0;i&rowCi++)
Vector score=new Vector();
String scoreInformation="";
for(int j=0;j&columnCj++)
score.add(table.getValueAt(i, j));
scoreInformation+=table.getValueAt(i, j);
allScore.add(score);
DBSQLManager dbsm=new DBSQLManager();
int[]resultCount=dbsm.callProcedureBatch(allScore);
System.out.println(scoreInformation);
catch(Exception e1)
e1.printStackTrace();
的感言:非常感谢您,帮了大忙,谢谢! 满意答案
executeBatch方法执行错误返回值应该是别的,调试看下。
stmt.executeBatch()执行的是一个整型。当其中的一条sql语句正确,执行成功,返回“1”当sql语句错误,没有返回值。请帮我想想解决办法,谢谢!
的感言:谢谢您!
等待您来回答
编程领域专家请帮我看看这个sql查询语句错误在哪里_百度知道
请帮我看看这个sql查询语句错误在哪里
建的表为 表1里面的字段是:电话号码、欠费金额、所属区域、负责人、付款情况;现在要在表1种查询所有欠费的电话号码、欠费金额、所属区域、负责人我写的sql语句(通过查询设计生成的语句)SELECT 表1.电话号码, 表1.欠费金额, 表1.负责人, 表1.所属区域FROM 表1WHERE (((表1.电话号码)=&欠款&));若我自己在sql视图中这样写SELECT 电话号码, 欠费金额, 负责人, 所属区域 FROM 表1 WHERE 付款情况=&欠款&
提问者采纳
付款情况='欠款'把&改成'
提问者评价
其他类似问题
sql查询的相关知识
等待您来回答
您可能关注的推广
下载知道APP
随时随地咨询
出门在外也不愁请问我这个sql语句哪里拼写错误。请帮忙修正。。谢谢_百度知道
请问我这个sql语句哪里拼写错误。请帮忙修正。。谢谢
&quot,String sql=&quot,,+yhid,&quot,+time,select * from Co_slct_schema where ptnr_id=&quot,equals(time)){
sql=sql+&quot, and schema_name=&quot, and create_date=&quot,
if(&quot,+name,,
if(&quot,equals(name)){
sql=sql+&quot,
提问者采纳
&quot,你的查询条件没有加引号改正,,String sql=&quot,下面那两个也一样,+yhi+&quot,&#39,select * from Co_slct_schema where ptnr_id=&#39,&quot,
String sql=&select * from Co_slct_schema where ptnr_id=&+yhid+&&;
if(name!=null){
System.out.println(yhid);
sql=sql+& and schema_name=&+name+&&;
if(time!=null){
sql=sql+& and create_date=&+time+&&;
}'=' 附近有语法错误。
请在帮忙看看。
sql=sql+& and schema_name=&+name+&&;你的name左边没有加单引号.应该是sql=sql+& and schema_name='&+name+&&;下面的那个time的左边也要加上单引号总之在System.out.println(sql);时要和数据库里的查询是一样的
提问者评价
总之在System.out.println(sql);时要和数据库里的查询是一样的 这一句
启发了我。很感谢 以后都知道了
其他类似问题
按默认排序
其他4条回答
(create_date是时间类型字段的话,mi,+name+&quot,&quot,,String sql=&quot,+time,&#39, and create_date=&quot,&quot,equals(name)){
sql=sql+&quot,select * from Co_slct_schema where ptnr_id=&quot,equals(time)){
sql=sql+&quot,)
},&quot,+yhid,
if(!&quot, 号)
if(!&quot,,sql=sql+&quot,&quot,写成这样,应该这样, and create_date=to_date(&#39,ss&#39,+time +&quot,,yyyy-mm-dd hh24,&#39,,,
(连接字符要加 &#39,&#39,)&quot, and schema_name=&#39,
String sql=&select * from Co_slct_schema where ptnr_id=&.
if(&&.equals(name)){
sql=sql.& and schema_name=&.
if(&&.equals(time)){
sql=sql.& and create_date=&.
} 其中里面的“+”号改为“.”
if(&&.equals(time)){
sql=sql+& and create_date=&+
}这里的时间前后要加''吧? if(&&.equals(time)){
sql=sql+& and create_date=‘&+time+&'&;
忘加引号了。
sql语句的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁查看: 954|回复: 5
[求助] 帮忙看看这段SQL数据库语句哪里错了? 大家来
{
& && & $notice='最近没有论坛公告';
}
if($discuz_uid && $newpm) {
& & & & & & & & require_once DISCUZ_ROOT.'./include/pmprompt.inc.php';
}
//首页焦点话题
&&$query = $db-&query(&SELECT subject ,message FROM {$tablepre}posts where tid=$tid&);
& & while($d = $db-&fetch_array($query)) {
& &$d[message] = cutstr($d[message], 125);
& &$digesttitle.=&&A href=viewthread.php?tid=$tid target=_blank&$d[subject]&/A&&;
& &$digestcontent.=&$d[message]&;
}
//网站分类数目统计
& & $query = $db-&query(&SELECT * FROM {$tablepre}forums&&WHERE type='forum'&);
& & while($forum = $db-&fetch_array($query)) {
& & & & $aposts1+=$forum['threads'];
& & & & $aposts2+=$forum['posts'];
& & & & $todayposts += forumtodayposts($forum);
//热点推荐TOP15
$hitthreads = '';
$query = $db-&query(&SELECT t.fid, f.name,t.author, t.tid, t.subject,t.views FROM {$tablepre}threads t LEFT JOIN {$tablepre}forums f ON f.fid=t.fid ORDER BY views DESC LIMIT 0, 15&);
while($thread = $db-&fetch_array($query)) {
& & & & $thread[subject] = cutstr($thread[subject], 50);
& & & & $hitthreads.=&&TR&&TD&【&A href='bbs.php?url=forumdisplay.php?fid=$thread[fid]' target=_blank&$thread[name]&/A&】&a href='viewthread.php?tid=$thread[tid]' title='作者:$thread[author] 浏览:$thread[views]' target=_blank&$thread[subject]&/A&&/TD&&TD width=120&&A class=a01 href='viewpro.php?username=$thread[author]' target=_blank&$thread[author]&/A&&/TD&&/TR&&;
}
//最新文章
$replythreads = '';
$query = $db-&query(&SELECT author, views, tid, subject, lastpost FROM {$tablepre}threads ORDER BY dateline DESC LIMIT 0, 9&);
while($thread = $db-&fetch_array($query)) {
& & & & $thread[subject] = cutstr($thread[subject], 32);
& & & & $thread[lastpost] = gmdate(&Y-m-j g:i&, $thread[lastpost] + $timeoffset * 3600);
& & & & $replythreads.=& &LI&&a href='viewthread.php?tid=$thread[tid]' title='作者:$thread[author] 回复:$thread[lastpost]' target=_blank&$thread[subject]&/A&&br /&&;
}
//今日发贴前3名
$month=date(n);
$date=date(j);
$year=date(Y);
$time=mktime(0,0,0,$month,$date,$year);
$query = $db-&query(&select count(p.pid) as num,p.authorid,p.author,me.avatar from cdb_posts p left join cdb_members m on p.authorid=m.uid left join cdb_memberfields me on p.authorid=me.uid where dateline&=$time group by authorid order by num desc limit 0,3&);
while($result=$db-&fetch_array($query)){
$poststar.=& &TD&&TABLE cellSpacing=0 cellPadding=0 width=95% border=0&&TBODY&&TR&&TD vAlign=bottom align=middle height=127&&TABLE cellSpacing=1 cellPadding=0 width=76 bgColor=#a8a8a8 border=0&&TBODY&&TR&&TD align=middle bgColor=#ffffff height=119&&a href=viewpro.php?uid=&.$result[authorid].& title='今日发贴;&.$result[num].&' target=_blank&&IMG height=113 src=&.$result[avatar].& width=70 border=0&&/a&&/TD&&/TR&&/TBODY&&/TABLE&&/TD&&/TR&&;
$poststar.=& &TR&&TD class=C4 style=FONT-SIZE: 12px align=middle&&A style=COLOR: #000; TEXT-DECORATION: underline href=viewpro.php?uid=&.$result[authorid].& target=_blank&&.$result[author].&&/A&&/TD&&/TR&&/TBODY&&/TABLE&&/TD&&;
}
//发贴总排行
$hotmember1 = '';
$query = $db-&query(&SELECT username, uid, posts FROM {$tablepre}members ORDER BY posts DESC LIMIT 0, 10&);
while($member = $db-&fetch_array($query)) {
& && & $hotmember1.=&&table border='0' width='80%' cellspacing='0' cellpadding='0' height=18&
& & & & & & & & &tr&
& & & & & & & & & & & & &td&&a href='viewpro.php?uid=$member[uid]'&$member[username]&/a&&/td&
& & & & & & & & & & & & &td align='right'&$member[posts]&br /&&/td&
& & & & & & & & &/tr&
& & & & &/table&&;
}
复制代码
是在首页调用时用的`&&可是有错误啊
我现在用的5.0& & 是不是数据库结构不一样?
另外 哪里有关于调用的文章?&&我是DZ新手``
我用在这的
大家帮我看看。。
main.php自动生成main.htm
我把query的发出来了。 演示里不显示的就是不能用的
&&帮我看看是哪句错了啊``
//网站分类数目统计
//热点推荐TOP15
//今日发贴前3名
&&好象就这三个不对啊&&看看
//网站分类数目统计
& & $query = $db-&query(&SELECT * FROM {$tablepre}forums&&WHERE type='forum'&);
& & while($forum = $db-&fetch_array($query)) {
& && &&&$aposts1+=$forum['threads'];
& && &&&$aposts2+=$forum['posts'];
& && &&&$todayposts += forumtodayposts($forum);
& && &&&}
复制代码
上面那段是哪里不对啊???~!?
还有下面那段!?& &现在就剩这两个了
//今日发贴前3名
$month=date(n);
$date=date(j);
$year=date(Y);
$time=mktime(0,0,0,$month,$date,$year);
$query = $db-&query(&select count(p.pid) as num,p.authorid,p.author,me.avatar from cdb_posts p left join cdb_members m on p.authorid=m.uid left join cdb_memberfields me on p.authorid=me.uid where dateline&=$time group by authorid order by num desc limit 0,3&);
while($result=$db-&fetch_array($query)){
$poststar.=& &TD&&TABLE cellSpacing=0 cellPadding=0 width=95% border=0&&TBODY&&TR&&TD vAlign=bottom align=middle height=127&&TABLE cellSpacing=1 cellPadding=0 width=76 bgColor=#a8a8a8 border=0&&TBODY&&TR&&TD align=middle bgColor=#ffffff height=119&&a href=viewpro.php?uid=&.$result[authorid].& title='今日发贴;&.$result[num].&' target=_blank&&IMG height=113 src=&.$result[avatar].& width=70 border=0&&/a&&/TD&&/TR&&/TBODY&&/TABLE&&/TD&&/TR&&;
$poststar.=& &TR&&TD class=C4 style=FONT-SIZE: 12px align=middle&&A style=COLOR: #000; TEXT-DECORATION: underline href=viewpro.php?uid=&.$result[authorid].& target=_blank&&.$result[author].&&/A&&/TD&&/TR&&/TBODY&&/TABLE&&/TD&&;
}
复制代码
高手来帮忙
高手来帮忙a
???????????
Powered by在access数据库SQL语句SELECT TOP 5 而显示是所有记录?这是哪里出问题了
[问题点数:20分,结帖人zhenjialong]
在access数据库SQL语句SELECT TOP 5 而显示是所有记录?这是哪里出问题了
[问题点数:20分,结帖人zhenjialong]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
相关帖子推荐:
本帖子已过去太久远了,不再提供回复功能。

我要回帖

 

随机推荐