WEB开发网
开发学院WEB开发Jsp Java操作Oracle数据库(建表,插数据,删除) 阅读

Java操作Oracle数据库(建表,插数据,删除)

 2008-01-05 09:10:18 来源:WEB开发网   
核心提示:import java.net.URL;import java.sql.*;public class Create { public Create() { }public static void main(String[] args){ String url = "jdbc:Oracle:thin:@1

  import java.net.URL;
import java.sql.*;

public class Create {
public Create() {
}
public static void main(String[] args){
String url = "jdbc:Oracle:thin:@10.0.1.3:1521:SDCDB";
String query = "CREATE TABLE MYFIRST" + "(id INT,name CHAR(10))";
String sql="insert into MYFIRST values('1','liming')";
String sql1="insert into MYFIRST values('2','mm')";
String sql2="delete MYFIRST where id=2";
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(url, "test", "test");
Statement stmt = conn.createStatement();
stmt.executeUpdate(query);
stmt.executeUpdate(sql);
stmt.executeUpdate(sql1);
stmt.executeUpdate(sql2);
System.out.PRintln("Create SUCcess!");
stmt.close();
conn.close();
}
catch(java.lang.ClassNotFoundException e){
System.err.print(e.getMessage());
}
catch(SQLException ex){
System.out.println("\n***SQLException caught ***\n");
}
}
}

Tags:Java 操作 Oracle

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接