java代码中字符串换行应该用连接符.先把整个语句写到一行里看看.

解决方案 »

  1.   

    另外,jdbc连接的代码一般都是写在try块里的。
      

  2.   

    String upd="create table Author(
                              Author_id integer not null primary key,
                              Author_name char(50));";结尾那个引号前面的分号去掉
      

  3.   

    我的代码是写在try里的啊
      可为什么public class createTable{} 的这个class都出错啊
      
     安装了mysql是不是还要在环境变量中配置一下啊?????????
      

  4.   

    给你贴一段简单的jdbc连接oracle的代码吧:import java.sql.*;
    import javax.sql.*;public class MyJdbc2 {
      public static void main(String args[]) {
        Connection connMy = null;
        ResultSet rsMy = null;
        Statement stmtMy = null;
        String url = "jdbc:oracle:thin:@localhost:1521:ooooora";
        try {
          Class.forName("oracle.jdbc.driver.OracleDriver");
          connMy = DriverManager.getConnection(url, "scott", "tiger");
          stmtMy = connMy.createStatement();      //对jdbc1表和jdbc2表的联合查询操作
          rsMy = stmtMy.executeQuery(
              "select jdbc1.id,jdbc1.jname,jdbc2.jdetail from jdbc1,jdbc2");
          while (rsMy.next()) {
            System.out.print(rsMy.getInt("id"));
            System.out.print("\t");
            System.out.print(rsMy.getString("jname"));
            System.out.print("\t");
            System.out.print(rsMy.getString("jdetail"));
            System.out.println();
          }      //对jdbc1表的插入操作
          stmtMy.executeUpdate("insert into jdbc1 values(22,'well done!')");      //对jdbc1表的修改操作
          stmtMy.executeUpdate("update jdbc1 set jname='ok!' where id=22");      //对jdbc1表和jdbc2表进行删除操作
          stmtMy.executeUpdate("delete jdbc2 where id2=22");
          stmtMy.executeUpdate("delete jdbc1 where id=22");      //释放资源
          rsMy.close();
          stmtMy.close();
          connMy.close();    }
        catch (Exception e) {
          e.printStackTrace();
        }
        finally {
          try {
            if (rsMy != null) {
              rsMy.close();
            }
            if (stmtMy != null) {
              stmtMy.close();
            }
            if (connMy != null) {
              connMy.close();
            }
          }
          catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
    }
      

  5.   

    连结数据库要用try/catch,另外就是换行+连结符,
    另外,登陆mysql的用户要有创健表的权限,当然,你上面的错误不是这个原因,仅仅提醒
      

  6.   

    谢谢各位朋友的帮助 (要用+连结符)
      现在我可以编译了 可得到class文件;
      可用java createTable时
      就会输出 classNotfoundException:could not locate driver
      我的代码内有这样一个捕获异常的代码:
        catch(classNotFoundException cnfe){
                     System.out.println("classNotFoundException:could not locate driver");}
      为什么会执行这个语句啊????
      

  7.   

    把驱动安装到classpath下,还有就是要注册驱动
      

  8.   

    直接放到WEB-INF\classes目录就行了
      

  9.   

    把数据库驱动放到你的应用的 WEB-INF\lib 下.这是实际企业开发中的一般用法.
      

  10.   

    听说要在classpath指向这个驱动程序是吗
     哪要怎么指向啊
      谢谢了