📄 testtablecreation.java
字号:
/* * TestTableCreation.java * * Created on December 27, 2001, 10:25 AM */package ch19;import java.sql.*;/** * * @author Stephen Potts * @version */public class TestTableCreation{ /** Creates new TestTableCreation */ public TestTableCreation() { } public static void main(String[] args) { String createStatement; try { //load the driver class Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //Specify the ODBC data source String sourceURL = "jdbc:odbc:TicketRequest"; //get a connection to the database Connection dbConn = DriverManager.getConnection(sourceURL); //If we get to here, no exception was thrown System.out.println("The database connection is " + dbConn); //Create the statement Statement statement1 = dbConn.createStatement(); String insertStatement; //////////////////////////////////////////////////////////// // Create the tables in the database // //////////////////////////////////////////////////////////// try { statement1.execute("drop table TicketRequest"); } catch (SQLException e) { System.out.println("table doesn't need to be dropped."); } //Add the table createStatement = "CREATE TABLE TicketRequest(CustID int PRIMARY KEY, " + "LastName VARCHAR(30), FirstName VARCHAR(30), " + "CruiseID int, destination VARCHAR(30), port VARCHAR(30), " + "sailing VARCHAR(30), numberOfTickets VARCHAR(30))"; System.out.println(createStatement); statement1.executeUpdate(createStatement); System.out.println("Table TicketRequest created."); //Flush and close dbConn.close(); }catch(ClassNotFoundException cnfe) { System.err.println(cnfe); } catch (SQLException sqle) { System.err.println(sqle); } catch (Exception e) { System.err.println(e); } }//main}//class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -