模板为
package com.jredu.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class selectDemo {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Class.forName("oracle.jdbc.OracleDriver");
String url = "jdbc:oracle:thin:@192.168.0.136:1521/orcl";
String user = "scott";
String password = "tiger";
Connection con = DriverManager.getConnection(url, user, password);
Statement st = con.createStatement();
String sql = " ";
int y = st1.executeUpdate(sql);
System.out.println(y);
st.close();
con.close();
增删改的sql的语句
String sql = "";
查的sql语句
String sql = "select * from sort1";
ResultSet result = st.executeQuery(sql);
while (result.next()) {
String name = result.getString("sname");
int id = result.getInt("sid");
System.out.println(id+name);
}
result.close();