2011-12-15 49 views
0

我試圖在Oracle數據庫上創建一個表:不能夠通過下面的Java代碼在Oracle創建表的數據庫使用ojdbc通過Java

import java.io.PrintStream; 
import java.sql.*; 

public class TestJDBC 
{ 

public TestJDBC() 
{ 
} 

public static void main(String args[]) 
{ 
    //String s = "Create table phone(fullname VARCHAR(30) NOT NULL,phnumber VARCHAR(30) NOT NULL)"; 
    //String s1 = "INSERT INTO phone VALUES ('Ted Nicholson', '201 555-1212')"; 
    //String s2 = "SELECT * FROM phone"; 
    try 
    { 
     Class.forName("oracle.jdbc.driver.OracleDriver"); 
    } 
    catch(ClassNotFoundException classnotfoundexception) 
    { 
     System.err.print("ClassNotFoundException: "); 
     System.err.println(classnotfoundexception.getMessage()); 
    } 
    try 
    { 
     System.out.println("Trying to connect..."); 
     Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@prophet.njit.edu:1521:course", "k45", "XXXX"); 
     System.out.println("connected!"); 
     Statement statement = connection.createStatement(); 
     statement.executeUpdate("Create table addressbook(first VARCHAR(30) NOT NULL, last VARCHAR(30) NOT NULL, address VARCHAR(30) NOT NULL, phone VARCHAR(15), email VARCHAR(30), dob date, Sex char(10)"); 
     //statement.executeUpdate(s); 
     System.out.println("Created Table."); 
     //statement.executeUpdate("INSERT INTO phone VALUES('Ted Nicholson', '201 555-1212'"); 
     //System.out.println("Inserted one record."); 
     //String s3; 
     //for(ResultSet resultset = statement.executeQuery(s2); resultset.next(); System.out.println(s3)) 
      //s3 = (new StringBuilder()).append(resultset.getString(1)).append(" ").append(resultset.getString(2)).toString(); 

     statement.close(); 
     connection.close(); 
    } 
    catch(SQLException sqlexception) 
    { 
     System.err.print("SQLException: "); 
     System.err.println(sqlexception.getMessage()); 
    } 
} 

}

我獲得以下錯誤:

Trying to connect...
connected!
SQLException: Io exception: Size Data Unit (SDU) mismatch
BUILD SUCCESSFUL (total time: 2 seconds)

+0

嘗試通過SQL Developer手動運行該表創建查詢 – emaillenin 2011-12-15 10:36:50

回答

1

本聲明:

Create table addressbook(first VARCHAR(30) NOT NULL, last VARCHAR(30) NOT NULL, address VARCHAR(30) NOT NULL, phone VARCHAR(15), email VARCHAR(30), dob date, Sex char(10) 

需要一個「)」。