package org.oracle.insert; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class InsertDeom { public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver"; public static final String DBURL = "jdbc:oracle:thin:@127.0.0.1:1521:ORCL"; public static final String DBUSER = "scott"; public static final String DBPASS = "tiger"; public static void main(String[] args) throws Exception{ Connection conn = null; Statement stmt = null; Class.forName(DBDRIVER); conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS); stmt = conn.createStatement(); String sql = "insert into person(name,age,birthday,salary)values('王五',22,TO_Date('1986-2-22','yyyy-mm-dd'),4000)"; stmt.executeUpdate(sql); stmt.close(); conn.close(); } }
××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
package org.oracle.select; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class ResultDeom { public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver"; public static final String DBURL = "jdbc:oracle:thin:@127.0.0.1:1521:ORCL"; public static final String DBUSER = "scott"; public static final String DBPASS = "tiger"; public static void main(String[] args) throws Exception{ Connection conn = null; Statement stmt = null; ResultSet rs = null; Class.forName(DBDRIVER); conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS); stmt = conn.createStatement(); // stmt.executeUpdate("insert into person(name,age,birthday,salary)values('李四',22,TO_Date('1986-2-22','yyyy-mm-dd'),4000)"); rs = stmt.executeQuery("select name,age,birthday,salary from person"); while(rs.next()){ System.out.print("name:"+rs.getString("name")+". "); System.out.print("age:"+rs.getInt("age")+". "); System.out.print("birthday:"+rs.getDate("birthday")+". "); System.out.println("salary:"+rs.getFloat("salary")+". "); } rs.close(); stmt.close(); conn.close(); } }