static Connection connection = null;
static Statement statement = null;
static ResultSet resultset = null;
/**
* @param args
* @throws SQLException
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
try{
connection = fetchConnection();
statement = connection.createStatement();
String sql = "select * from temp";
resultset = statement.executeQuery(sql);
while(resultset.next()){
System.out.println("id "+resultset.getLong("id")+" |name "+resultset.getString("name"));
}
//String sql = "insert into temp (id,name) values(7,'qiban')";
//int updateLines=statement.executeUpdate(sql);
//System.out.println(updateLines);
}
catch(Exception e){
e.printStackTrace();
}
finally{
statement.close();
connection.close();
}
}
public static Connection fetchConnection(){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
String url ="jdbc:oracle:thin:@192.168.119.109:1521:orclliu";
String user = "liuyi";
String pwd = "liu";
return DriverManager.getConnection(url,user,pwd);
}
catch(Exception e){
e.printStackTrace();
return null;
}
}
}