jdbc问题

11寸 2006-03-19 02:23:19
想要向数据库中插入数据,但没有作用,可是select、create table都好使,就是insert没结果,请高人指点,能不能使其他地方的问题?原程序如下:
public class oraDB {

Connection connect = null;
ResultSet rs = null;
String connectODBC="jdbc:odbc:MOADB";

/**设置驱动程序
*
*
*/
public oraDB(){

try{
//oracle数据库驱动
//Class.forName("oracle.jdbc.driver.OracleDriver");
//access数据库驱动
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
e.printStackTrace();
}

}

/**
* 执行数据查询
* @param sql 查询语句
* @return rs ResultSet类型
*/
public ResultSet executeQuery(String sql){
try{
//oracle连接语句
//connect = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:MOA","system","root");
//access连接语句
connect = DriverManager.getConnection(connectODBC,"admin","root");
Statement stmt = connect.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery(sql);

}
catch(SQLException sqlEX){
sqlEX.printStackTrace();
}
return rs;
}

/**
* 执行数据更新
* @param sql 查询语句
* @return
*/
public int executeUpdate(String sql){
int result = 0;
try{
//oracle连接语句
//connect = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:MOA","system","root");
//access连接语句
connect = DriverManager.getConnection(connectODBC,"admin","root");
Statement stmt = connect.createStatement();
result = stmt.executeUpdate(sql);

}
catch(SQLException sqlEX){
System.err.println(sqlEX.getMessage());
}
return result;
}

/**
* 关闭与数据库的连接
*
*/
public void close(){
if(connect!= null){
try{
connect.close();
connect = null;
}
catch(SQLException sqlEX){
System.err.println(sqlEX.getMessage());
}
}
}



/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
ResultSet res = null;
int resn;
String sql = new String("");
sql = "insert into col_link values('ASP中华网','http://www.aspcn.com')";
oraDB db = new oraDB();

System.out.println(sql);
resn = db.executeUpdate(sql);
System.out.println(resn);

}

}
...全文
145 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
goalshx 2006-03-20
  • 打赏
  • 举报
回复
我最近也遇到这个问题 受教了
11寸 2006-03-19
  • 打赏
  • 举报
回复
贴子回复次数大于跟给分次数是什么意思?
不能结帖?
xiongbing528 2006-03-19
  • 打赏
  • 举报
回复
单独的sql语句是没错。呵呵。.可能是不匹配..
11寸 2006-03-19
  • 打赏
  • 举报
回复
问题解决了,谢谢各位。如果您感兴趣,这是解决问题的地址:http://book.77169.org/data/web5404/20050412/20050412__3816448.html
xiongbing528 2006-03-19
  • 打赏
  • 举报
回复
单独的sql语句是没错。呵呵。.可能是不匹配..
11寸 2006-03-19
  • 打赏
  • 举报
回复
匹配的
AI老叫瘦 2006-03-19
  • 打赏
  • 举报
回复
values('ASP中华网','http://www.aspcn.com')中的列名是否与表中的列相匹配
wzjcntlqs 2006-03-19
  • 打赏
  • 举报
回复
放在查询分析器中执行呢
AI老叫瘦 2006-03-19
  • 打赏
  • 举报
回复
insert into col_link values('ASP中华网','http://www.aspcn.com')这个语句可以单独在oracle中执行?
11寸 2006-03-19
  • 打赏
  • 举报
回复
没有任何错误信息
interpb 2006-03-19
  • 打赏
  • 举报
回复
错误信息是什么啊

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧