Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate » Other DB  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 java+access表数据不能修改
dreamtobetrue





发贴: 18
积分: 0
于 2006-09-25 08:08 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
import java.sql.*;
public class Access
{
  
  public static void main(String[] args)
  {
    try
    {
   String dburl= "jdbc:odbc:acc";
            String dbuser="acc";
            String dbpassword="123456";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn1 = DriverManager.getConnection(dburl,dbuser,dbpassword);
           Statement stmt1 = conn1.createStatement();
           stmt1.executeUpdate("insert into favs (f_title,f_url,f_username,f_time) values ('你的','www.tom.com ','挪威的森林','2006-2-19 12:45:19')");
           /*ResultSet rs=stmt1.executeQuery("select * from favs");
             while(rs.next())
      {
            String title=rs.getString("f_title");
            System.out.println(title);
      }*/
      
    }
    catch (ClassNotFoundException cnfe)
    {
      cnfe.printStackTrace();
}
catch(SQLException cnfe)
{
cnfe.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
    }
  }
}
程序没有抱错,编译运行正常,我感觉是不是我的Access数据库设置有问题。
望各位指点!



^_^笑着面对生活
作者 Re:java+access表数据不能修改 [Re:dreamtobetrue]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-09-25 09:36 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Don't double post!

Have you checked whether your mdb file is not read-only?
Have you tried running the insert statement inside Access?



作者 Re:java+access表数据不能修改 [Re:dreamtobetrue]
dreamtobetrue





发贴: 18
积分: 0
于 2006-09-25 17:13 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
元老同志,多谢
1)我查过我的Access文件,不是只读形式的,而且数据源也不是只读的
2)我在我的Access文件中可以直接插入信息,但是用程序直接操作insert
就会失败。
3)我换了电脑试了试,还是没有成功。接着office 2000替换了office 2003
还是同样的问题。
感觉比较困惑,因为我的程序我自己感觉是没有问题的,应该是Access数据库的问题,但不知道问题所在。



^_^笑着面对生活
作者 Re:java+access表数据不能修改 [Re:dreamtobetrue]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-09-25 18:04 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
check the return value of executeUpdate and see whether it is 0

try adding a ; at the end of the insert statement string

try PreparedStatement
I am wondering if f_time is of type DateTime, I won't pass a String to it like that, though it may be allowed.

程序没有


Just did a Google search. and found this
http://forum.java.sun.com/thread.jspa?threadID=597260&messageID=3178446
or
http://forum.java.sun.com/thread.jspa?threadID=712716&messageID=4122465


why edited on 2006-09-25 18:15

作者 Re:java+access表数据不能修改 [Re:dreamtobetrue]
JiafanZhou



版主


发贴: 736
积分: 61
于 2006-09-25 18:27 user profilesend a private message to usersend email to JiafanZhousearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
哈哈,我知道你的问题。。但是我不是很清楚了。。

你的问题是没有把Connection 关掉。。conn1.close()还是stmt.close()我记不清了。

工作了以后快来谢谢我。。

嘉帆。



When I was a kid I used to pray every night for a new bike. Then I realized that The Lord doesn't work that way, so I stole one and asked him to forgive me.
作者 Re:java+access表数据不能修改 [Re:dreamtobetrue]
dreamtobetrue





发贴: 18
积分: 0
于 2006-09-26 10:14 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
多谢元老同志指出我的错误!
我以后会注意细节的。



作者 Re:java+access表数据不能修改 [Re:dreamtobetrue]
dreamtobetrue





发贴: 18
积分: 0
于 2006-09-26 10:16 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
HenryShanley
多谢!果然是这个问题,我加上去之后就成功了。
但是能不能告诉我为什么,因为我在操作别的数据库如MS SQL ,MySQL的时候
没有关闭连接,同样可以进行插入或者Set操作。



作者 Re:java+access表数据不能修改 [Re:dreamtobetrue]
JiafanZhou



版主


发贴: 736
积分: 61
于 2006-09-27 06:07 user profilesend a private message to usersend email to JiafanZhousearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
因为我也有犯过你同样的问题,你真得很走运,我记得我当时调试了很长很长时间才知道原因....痛苦啊
一段3000行的代码被我花了8个小时删到你上面的那几行代码才知道问题所在..血和泪阿..至于为什么我也不知道.
你还可以试一下同样的代码在GUI里面就可以运行的..很怪的

我已经从JDBC到ORM转型了..赶快去学Hibernate吧

嘉帆



When I was a kid I used to pray every night for a new bike. Then I realized that The Lord doesn't work that way, so I stole one and asked him to forgive me.
作者 Re:java+access表数据不能修改 [Re:dreamtobetrue]
why

問題兒童

总版主


发贴: 4629
积分: 388
于 2006-09-27 11:42 user profilesend a private message to usersend email to whysearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
dreamtobetrue wrote:
HenryShanley
多谢!果然是这个问题,我加上去之后就成功了。
但是能不能告诉我为什么,因为我在操作别的数据库如MS SQL ,MySQL的时候
没有关闭连接,同样可以进行插入或者Set操作。

In one of the link I mentioned above, it says:
You have to close the connection for Access to refelct the data changes. I believe the reason is mainly because Access is not a pure database and acts somewhat like file I/O.

In fact, you should make it a practice to close all the JDBC resources, i.e. ResultSet, Statement [includes PreparedStatement and CallableStatement] and the Connection Moon in every JDBC code and avoid all the problems that might follow later on. It is better to do so in a finally block to ensure that the resources are always closed.

Well, this is not really a reason but a guess.



作者 Re:java+access表数据不能修改 [Re:why]
nt





发贴: 9
积分: 0
于 2006-09-27 13:43 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
强人啊,不关connection ,居然还讨论.....


Accrual.

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923