一段很简单很简单的jdbc源码,但就是有问题!!!

birdyanyan1982 2003-05-17 11:01:19
import java.sql.*;

class test
{
public static void main(String[] args)
{
Connection con=null;
try
{
Class.forName("oracle.jdbc.OracleDriver");
}
catch(Exception e)
{
System.out.println("could not load drive!");
System.exit(-1);
}
try
{
con=DriverManager.getConnection(args[0]);
}
catch(Exception e)
{
System.out.println("can not get connection!");
System.out.println(e.getMessage());
System.exit(-1);
}
try
{
Statement stmt=con.createStatement();
int res=stmt.executeUpdate("create table employees3"
+"(emp_id number(10,0)not null primary key"
+",first_name varchar2(20)not null"
+",surname varchar2(100)not null)");
System.out.println("create Employee tables res="+res);
stmt.executeUpdate("insert into employees3"
+"values(1,'gale','bird')");
stmt.executeUpdate("insert into employees3"
+"values(2,'Jack','London')");
System.out.println("create two employees res");
stmt.close();
con.close();
}
catch(Exception e)
{
System.out.println("unexperted sql errors!");
System.out.println(e.getMessage());
System.exit(-1);
}

}
}

import java.sql.*;

class test
{
public static void main(String[] args)
{
Connection con=null;
try
{
Class.forName("oracle.jdbc.OracleDriver");
}
catch(Exception e)
{
System.out.println("could not load drive!");
System.exit(-1);
}
try
{
con=DriverManager.getConnection(args[0]);
}
catch(Exception e)
{
System.out.println("can not get connection!");
System.out.println(e.getMessage());
System.exit(-1);
}
try
{
Statement stmt=con.createStatement();
int res=stmt.executeUpdate("create table employees3"
+"(emp_id number(10,0)not null primary key"
+",first_name varchar2(20)not null"
+",surname varchar2(100)not null)");
System.out.println("create Employee tables res="+res);
res+=stmt.executeUpdate("insert into employees3"
+"values(1,'gale','bird')");
res+=stmt.executeUpdate("insert into employees3"
+"values(2,'Jack','London')");
System.out.println("create two employees res="+res);
stmt.close();
con.close();
}
catch(Exception e)
{
System.out.println("unexperted sql errors!");
System.out.println(e.getMessage());
System.exit(-1);
}

}
}

---------------------------------------------------------------------

于是我执行java test
"jdbc:oracle:thin:system/birdyan@localhost:1521:birdyan"
birdyan是我数据库的名字,执行后输出如下:
create Employee tables res=0
unexperted sql errors!
缺少select关键字

看来是插入时的问题,问题在哪里呢?和select什么关系啊?
...全文
47 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
snicker 2003-05-18
  • 打赏
  • 举报
回复
它大概以为你要写成 insert into table select.... 的形式
snicker 2003-05-18
  • 打赏
  • 举报
回复
res+=stmt.executeUpdate("insert into employees3"
+" values(1,'gale','bird')");
res+=stmt.executeUpdate("insert into employees3"
+" values(2,'Jack','London')");
----------------------------------------------------
values前面加两空格
Sheepy 2003-05-18
  • 打赏
  • 举报
回复
你把最后一个try-catch分细一点,看看问题出在哪一步。
game4cn 2003-05-18
  • 打赏
  • 举报
回复
帮忙顶
birdyanyan1982 2003-05-18
  • 打赏
  • 举报
回复
不行啊,还是那样。
birdyanyan1982 2003-05-18
  • 打赏
  • 举报
回复
从抛出的异常看,应该不知在这里的问题啊,我试试。
game4cn 2003-05-18
  • 打赏
  • 举报
回复
Class.forName("oracle.jdbc.OracleDriver");
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

这个是什么,我用的是O8i 817 中oracle.jdbc.driver.OracleDriver()

在class12.zip中~~

是不是和这个有一些关系,楼主自己试试,我没有环境~~

birdyanyan1982 2003-05-18
  • 打赏
  • 举报
回复
哦,不好意思,两端代码,以下面的为准。
birdyanyan1982 2003-05-18
  • 打赏
  • 举报
回复
呵呵,就是空格的问题,好像在mysql中不存在这个问题哦。
怎么oracle有这种问题呢?
谢谢了。

62,614

社区成员

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

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