java

public static void main(String[] args) {
		Connection connection = DBConnection.getConn();
		Statement statement = null;
		ResultSet  resultSet = null;
		int rowCount;
		boolean isResultSet;
		try {
			 statement  =  connection.createStatement();
			 String sql = JOptionPane.showInputDialog("请输入一个SQL语句:");
			 isResultSet = statement.execute(sql);
			 if(isResultSet ){
				 resultSet = statement.getResultSet();
				 while(resultSet.next()){
					System.out.println("name:"+resultSet.getString("name"));  
					System.out.println("age:"+resultSet.getString("age"));
					System.out.println("sex:"+resultSet.getString("sex"));
				 }
			 }else{
				 rowCount = statement.getUpdateCount();
				 System.out.println("所更新的行数为"+rowCount+"行");
			 	}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			DBConnection.close(connection, statement, resultSet);
		}
	}
 

你可能感兴趣的:(java,sql)