package portal;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
	public static void main(String[] args) throws ClassNotFoundException, SQLException{
		Class.forName("org.postgresql.Driver");
		
	
		Connection con = DriverManager.getConnection("jdbc:postgresql://192.168.56.209:5432/kexiu", "postgres", "postgres");
		try{
			try{
			con.setAutoCommit(false);
			Statement st = con.createStatement();
			try{
				try{
				st.executeUpdate("insert into tt(id,name)values(9,'123')");
				}catch(SQLException e){
					String sqlState = e.getSQLState();
					if("23505".equals(sqlState)){
						st.executeUpdate("insert into tt(id,name)values(9,'1ui')");
					}else
						throw e;
				}
			}finally{
				st.close();
			}
			con.commit();
		}catch(SQLException e){
			System.out.println(e.getErrorCode());
			System.out.println(e.getSQLState());
			System.out.println("============");
			e.printStackTrace();
		}
		}finally{
			try{
				con.close();
			}catch(SQLException e){}
		}
		
		
		
		
	}
}
