import java.sql.*;
import java.io.*;
public class ex10_1
{
public static void main(String[] args) throws Exception
{
Statement stmt = null;
ResultSet rs = null;
Connection conn=null;
String url="jdbc:oracle:thin:@192.168.57.128:1521:bule";
Class.forName("oracle.jdbc.driver.OracleDriver");//加载驱动
String uname="hr";
String passwd="hr1234";
conn=DriverManager.getConnection(url,uname,passwd);
stmt=conn.createStatement(); //创建Statement对象
rs=stmt.executeQuery("Select * From person"); //查询表
while(rs.next()) //显示所有记录的ID和姓名
{
System.out.print(rs.getInt("id")+" ");
System.out.println(rs.getString("name")+" ");
};
stmt.executeUpdate("INSERT INTO person VALUES(9,'林时',3,'accountant',2000,4)"); //添加一条记录
System.out.println("添加数据后的信息为");
rs=stmt.executeQuery("Select * From person"); //查询表格
while(rs.next()) //显示
{
System.out.print(rs.getInt("id")+" ");
System.out.println(rs.getString("name")+" ");
};
stmt.executeUpdate("DELETE FROM person WHERE name='临时'");
//删除名字为“临时”的记录
System.out.println("删除数据后的信息为:");
rs=stmt.executeQuery("Select * From person"); //查询表格
while(rs.next()) //显示
{
System.out.print(rs.getInt("id")+" ");
System.out.println(rs.getString("name")+" ");
};
stmt.close(); //关闭语句
conn.close(); //关闭连接
}
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:395)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1102)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:320)
... 7 more
lijikai1937
lijikai1937
相关分类